Updated Gatsby mock: fluid images returned by useStaticQuery

This commit is contained in:
gianantoniopini
2020-12-14 15:05:03 +01:00
parent d51201d6f2
commit 942d8a0120

View File

@ -1,8 +1,28 @@
const React = require(`react`); import React from 'react';
const gatsby = jest.requireActual(`gatsby`); const Gatsby = jest.requireActual('gatsby');
const fluidImagesShapeMock = [
{
aspectRatio: 2,
src: `test_image.jpg`,
srcSet: `some srcSet`,
srcSetWebp: `some srcSetWebp`,
sizes: `(max-width: 600px) 100vw, 600px`,
base64: `string_of_base64`,
},
{
aspectRatio: 3,
src: `test_image_2.jpg`,
srcSet: `some other srcSet`,
srcSetWebp: `some other srcSetWebp`,
sizes: `(max-width: 600px) 100vw, 600px`,
base64: `string_of_base64`,
media: `only screen and (min-width: 768px)`,
},
];
module.exports = { module.exports = {
...gatsby, ...Gatsby,
graphql: jest.fn(), graphql: jest.fn(),
Link: jest.fn().mockImplementation(({ to, ...rest }) => Link: jest.fn().mockImplementation(({ to, ...rest }) =>
React.createElement(`a`, { React.createElement(`a`, {
@ -22,13 +42,7 @@ module.exports = {
}, },
file: { file: {
childImageSharp: { childImageSharp: {
fluid(maxWidth = 512) { fluid: fluidImagesShapeMock[0],
base64;
aspectRatio;
src;
srcSet;
sizes;
},
}, },
}, },
}), }),