From f5d9aa2f9e5c564a75bded35dac9af956a8e70ca Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Fri, 29 Apr 2022 09:55:41 -0700 Subject: [PATCH] add unit tests --- .../src/components/__tests__/hooks.ts | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/gatsby-plugin-image/src/components/__tests__/hooks.ts b/packages/gatsby-plugin-image/src/components/__tests__/hooks.ts index 83855288d16aa..478d62b2df7ca 100644 --- a/packages/gatsby-plugin-image/src/components/__tests__/hooks.ts +++ b/packages/gatsby-plugin-image/src/components/__tests__/hooks.ts @@ -25,14 +25,19 @@ const node: Node = { }, } -const dataParent = { +const imageDataParent = { ...node, gatsbyImageData: imageData, } +const imageParent = { + ...node, + gatsbyImage: imageData, +} + const fileNode = { ...node, - childImageSharp: dataParent, + childImageSharp: imageDataParent, } const getImageDataArgs: IGetImageDataArgs = { @@ -147,13 +152,21 @@ describe(`The image helper functions`, () => { it(`returns the same data if passed gatsbyImageData`, () => { expect(getImage(imageData)).toEqual(imageData) }) + it(`returns the same data if passed gatsbyImage`, () => { + expect(getImage(imageData)).toEqual(imageData) + }) it(`gets an image from a FileNode`, () => { expect(getImage(fileNode)?.images.fallback?.src).toEqual(`imagesrc.jpg`) }) - it(`gets an image from an IGatsbyImageDataParent`, () => { - expect(getImage(dataParent)?.images.fallback?.src).toEqual(`imagesrc.jpg`) + it(`gets an image from an IGatsbyImageDataParent/IGatsbyImageParent`, () => { + expect(getImage(imageDataParent)?.images.fallback?.src).toEqual( + `imagesrc.jpg` + ) + expect(getImage(imageParent)?.images.fallback?.src).toEqual( + `imagesrc.jpg` + ) }) it(`returns undefined from an invalid object`, () => { expect(getImage(node)).toBeUndefined() @@ -177,8 +190,9 @@ describe(`The image helper functions`, () => { expect(getSrc(fileNode)).toEqual(`imagesrc.jpg`) }) - it(`gets src from an IGatsbyImageDataParent`, () => { - expect(getSrc(dataParent)).toEqual(`imagesrc.jpg`) + it(`gets src from an IGatsbyImageDataParent/IGatsbyImageParent`, () => { + expect(getSrc(imageDataParent)).toEqual(`imagesrc.jpg`) + expect(getSrc(imageParent)).toEqual(`imagesrc.jpg`) }) it(`returns undefined from an invalid object`, () => { @@ -202,8 +216,9 @@ describe(`The image helper functions`, () => { expect(getSrcSet(fileNode)).toEqual(`imagesrcset.jpg 1x`) }) - it(`gets srcSet from an IGatsbyImageDataParent`, () => { - expect(getSrcSet(dataParent)).toEqual(`imagesrcset.jpg 1x`) + it(`gets srcSet from an IGatsbyImageDataParent/IGatsbyImageParent`, () => { + expect(getSrcSet(imageDataParent)).toEqual(`imagesrcset.jpg 1x`) + expect(getSrcSet(imageParent)).toEqual(`imagesrcset.jpg 1x`) }) it(`returns undefined from an invalid object`, () => {