@@ -4,14 +4,24 @@ import {
44 toMatchImageSnapshot ,
55 updateSnapshotState ,
66} from "jest-image-snapshot" ;
7+ import sharp from "sharp" ;
78
8- it ( "should be able to use toMatchImageSnapshot in a test" , ( ) => {
9+ it ( "should be able to use toMatchImageSnapshot in a test" , async ( ) => {
910 expect . extend ( { toMatchImageSnapshot } ) ;
1011
11- expect ( 400 ) . toMatchImageSnapshot ( ) ;
12+ expect (
13+ await sharp ( {
14+ create : {
15+ background : { b : 0 , g : 255 , r : 0 } ,
16+ channels : 3 ,
17+ height : 48 ,
18+ width : 48 ,
19+ } ,
20+ } ) . png ( ) . toBuffer ( ) ,
21+ ) . toMatchImageSnapshot ( ) ;
1222} ) ;
1323
14- it ( "should be able to use configureToMatchImageSnapshot in a test" , ( ) => {
24+ it ( "should be able to use configureToMatchImageSnapshot in a test" , async ( ) => {
1525 const matchFn = configureToMatchImageSnapshot ( {
1626 allowSizeMismatch : true ,
1727 noColors : true ,
@@ -25,10 +35,19 @@ it("should be able to use configureToMatchImageSnapshot in a test", () => {
2535 } ) ;
2636 expect . extend ( { toMatchImageSnapshot : matchFn } ) ;
2737
28- expect ( "Me" ) . toMatchImageSnapshot ( ) ;
38+ expect (
39+ await sharp ( {
40+ create : {
41+ background : { b : 0 , g : 255 , r : 0 } ,
42+ channels : 3 ,
43+ height : 48 ,
44+ width : 48 ,
45+ } ,
46+ } ) . png ( ) . toBuffer ( ) ,
47+ ) . toMatchImageSnapshot ( ) ;
2948} ) ;
3049
31- it ( "Should be able to use configuration directly in toMatchImageSnapshot" , ( ) => {
50+ it ( "Should be able to use configuration directly in toMatchImageSnapshot" , async ( ) => {
3251 expect . extend ( { toMatchImageSnapshot } ) ;
3352
3453 const options : MatchImageSnapshotOptions = {
@@ -52,27 +71,91 @@ it("Should be able to use configuration directly in toMatchImageSnapshot", () =>
5271 failureThresholdType : "percent" ,
5372 } ;
5473
55- expect ( "Me" ) . toMatchImageSnapshot ( options ) ;
74+ expect (
75+ await sharp ( {
76+ create : {
77+ background : { b : 0 , g : 255 , r : 0 } ,
78+ channels : 3 ,
79+ height : 48 ,
80+ width : 48 ,
81+ } ,
82+ } ) . png ( ) . toBuffer ( ) ,
83+ ) . toMatchImageSnapshot ( options ) ;
5684} ) ;
5785
58- it ( "Should be able to use string as customSnapshotIdentifier" , ( ) => {
86+ it ( "Should be able to use string as customSnapshotIdentifier" , async ( ) => {
5987 const options : MatchImageSnapshotOptions = {
6088 customSnapshotIdentifier : "string identifier" ,
6189 } ;
6290
63- expect ( "Me" ) . toMatchImageSnapshot ( options ) ;
91+ expect (
92+ await sharp ( {
93+ create : {
94+ background : { b : 0 , g : 255 , r : 0 } ,
95+ channels : 3 ,
96+ height : 48 ,
97+ width : 48 ,
98+ } ,
99+ } ) . png ( ) . toBuffer ( ) ,
100+ ) . toMatchImageSnapshot ( options ) ;
64101} ) ;
65102
66- it ( "Should be able to use callback as customSnapshotIdentifier" , ( ) => {
103+ it ( "Should be able to use callback as customSnapshotIdentifier" , async ( ) => {
67104 const options : MatchImageSnapshotOptions = {
68105 customSnapshotIdentifier : ( ) => "string identifier" ,
69106 } ;
70107
71- expect ( "Me" ) . toMatchImageSnapshot ( options ) ;
108+ expect (
109+ await sharp ( {
110+ create : {
111+ background : { b : 0 , g : 255 , r : 0 } ,
112+ channels : 3 ,
113+ height : 48 ,
114+ width : 48 ,
115+ } ,
116+ } ) . png ( ) . toBuffer ( ) ,
117+ ) . toMatchImageSnapshot ( options ) ;
72118} ) ;
73119
74120it ( "mutates original state" , ( ) => {
75121 const originalState = { some : "value" } ;
76122 updateSnapshotState ( originalState , { another : "val" } ) ;
77123 expect ( originalState ) . toEqual ( { some : "value" , another : "val" } ) ;
78124} ) ;
125+
126+ it ( "should be able to use toMatchImageSnapshot without expect" , async ( ) => {
127+ const result = toMatchImageSnapshot . call (
128+ expect . getState ( ) ,
129+ await sharp ( {
130+ create : {
131+ background : { b : 0 , g : 255 , r : 0 } ,
132+ channels : 3 ,
133+ height : 48 ,
134+ width : 48 ,
135+ } ,
136+ } ) . png ( ) . toBuffer ( ) ,
137+ {
138+ allowSizeMismatch : true ,
139+ } ,
140+ ) ;
141+ expect ( result . pass ) . toEqual ( true ) ;
142+ } ) ;
143+
144+ it ( "should be able to use configureToMatchImageSnapshot without expect" , async ( ) => {
145+ const matchFn = configureToMatchImageSnapshot ( {
146+ allowSizeMismatch : true ,
147+ } ) ;
148+
149+ const result = matchFn . call (
150+ expect . getState ( ) ,
151+ await sharp ( {
152+ create : {
153+ background : { b : 0 , g : 255 , r : 0 } ,
154+ channels : 3 ,
155+ height : 48 ,
156+ width : 48 ,
157+ } ,
158+ } ) . png ( ) . toBuffer ( ) ,
159+ ) ;
160+ expect ( result . pass ) . toEqual ( true ) ;
161+ } ) ;
0 commit comments