@@ -8,6 +8,13 @@ import { PixelmatchConfig } from './pixelmatch.types';
88
99const mockPixelmatch = jest . fn ( ) ;
1010
11+ // Helper to create a Uint8Array for a PNG of given dimensions
12+ const createUint8ArrayForPng = ( width : number , height : number ) : Uint8Array => {
13+ const png = new PNG ( { width, height } ) ;
14+ // Access the underlying buffer and create a Uint8Array view
15+ return new Uint8Array ( png . data . buffer , png . data . byteOffset , png . data . byteLength ) ;
16+ } ;
17+
1118const initService = async ( { getImageMock = jest . fn ( ) , saveImageMock = jest . fn ( ) , deleteImageMock = jest . fn ( ) } ) => {
1219 const module : TestingModule = await Test . createTestingModule ( {
1320 providers : [
@@ -129,6 +136,12 @@ describe('getDiff', () => {
129136 mockPixelmatch . mockReturnValueOnce ( 5 ) ;
130137 service = await initService ( { saveImageMock, getImageMock } ) ;
131138
139+ const testConfig = {
140+ allowDiffDimensions : true ,
141+ ignoreAntialiasing : true ,
142+ threshold : 0.1 ,
143+ } ;
144+
132145 const result = await service . getDiff (
133146 {
134147 baseline : 'image' ,
@@ -137,31 +150,18 @@ describe('getDiff', () => {
137150 ignoreAreas : [ ] ,
138151 saveDiffAsFile : true ,
139152 } ,
140- {
141- allowDiffDimensions : true ,
142- ignoreAntialiasing : true ,
143- threshold : 0.1 ,
144- }
153+ testConfig
145154 ) ;
146155
147156 expect ( mockPixelmatch ) . toHaveBeenCalledWith (
148- new PNG ( {
149- width : 2 ,
150- height : 5 ,
151- } ) . data ,
152- new PNG ( {
153- width : 2 ,
154- height : 5 ,
155- } ) . data ,
156- new PNG ( {
157- width : 2 ,
158- height : 5 ,
159- } ) . data ,
157+ createUint8ArrayForPng ( 2 , 5 ) ,
158+ createUint8ArrayForPng ( 2 , 5 ) ,
159+ createUint8ArrayForPng ( 2 , 5 ) ,
160160 2 ,
161161 5 ,
162162 {
163- includeAA : true ,
164- threshold : 0.1 ,
163+ includeAA : testConfig . ignoreAntialiasing ,
164+ threshold : testConfig . threshold ,
165165 }
166166 ) ;
167167 expect ( saveImageMock ) . toHaveBeenCalledTimes ( 1 ) ;
0 commit comments