From 942d8a01202771ed47d88fed7e13d964487d73dc Mon Sep 17 00:00:00 2001 From: gianantoniopini <63844628+gianantoniopini@users.noreply.github.com> Date: Mon, 14 Dec 2020 15:05:03 +0100 Subject: [PATCH] Updated Gatsby mock: fluid images returned by useStaticQuery --- __mocks__/gatsby.js | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/__mocks__/gatsby.js b/__mocks__/gatsby.js index c9c0bae4..fa0835ad 100644 --- a/__mocks__/gatsby.js +++ b/__mocks__/gatsby.js @@ -1,8 +1,28 @@ -const React = require(`react`); -const gatsby = jest.requireActual(`gatsby`); +import React from 'react'; +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 = { - ...gatsby, + ...Gatsby, graphql: jest.fn(), Link: jest.fn().mockImplementation(({ to, ...rest }) => React.createElement(`a`, { @@ -22,13 +42,7 @@ module.exports = { }, file: { childImageSharp: { - fluid(maxWidth = 512) { - base64; - aspectRatio; - src; - srcSet; - sizes; - }, + fluid: fluidImagesShapeMock[0], }, }, }),