@@ -21,33 +21,48 @@ describe('buildSrcSet', () => {
21
21
expect ( firstSrcSet [ 1 ] ) . toMatch ( / ^ [ 0 - 9 ] + w $ / ) ;
22
22
} ) ;
23
23
24
- it ( 'custom widths are passed to imgix-core-js' , ( ) => {
25
- jest . resetModules ( ) ;
26
- jest . mock ( 'imgix-core-js' ) ;
27
- const { buildImgixClient } = require ( '@/plugins/vue-imgix/' ) ;
28
- const ImgixClient = require ( 'imgix-core-js' ) ;
29
- const ImgixMock = {
30
- settings : { } ,
31
- buildSrcSet : jest . fn ( ) ,
32
- buildURL : jest . fn ( ) ,
33
- } ;
34
- ImgixClient . mockImplementation ( ( ) => ImgixMock ) ;
35
-
36
- const client = buildImgixClient ( {
37
- domain : 'testing.imgix.net' ,
24
+ describe ( 'srcset generation' , ( ) => {
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ let mockImgixClient : any ;
27
+ let vueImgixClient : IVueImgixClient ;
28
+ beforeEach ( ( ) => {
29
+ jest . resetModules ( ) ;
30
+ jest . mock ( 'imgix-core-js' ) ;
31
+ const { buildImgixClient } = require ( '@/plugins/vue-imgix/' ) ;
32
+ const ImgixClient = require ( 'imgix-core-js' ) ;
33
+ mockImgixClient = {
34
+ settings : { } ,
35
+ buildSrcSet : jest . fn ( ) ,
36
+ buildURL : jest . fn ( ) ,
37
+ } ;
38
+ ImgixClient . mockImplementation ( ( ) => mockImgixClient ) ;
39
+ vueImgixClient = buildImgixClient ( {
40
+ domain : 'testing.imgix.net' ,
41
+ } ) ;
38
42
} ) ;
43
+ afterAll ( ( ) => {
44
+ jest . resetAllMocks ( ) ;
45
+ jest . resetModules ( ) ;
46
+ } ) ;
47
+ it ( 'custom widths are passed to imgix-core-js' , ( ) => {
48
+ vueImgixClient . buildSrcSet ( 'image.jpg' , { } , { widths : [ 100 , 200 ] } ) ;
39
49
40
- client . buildSrcSet ( 'image.jpg' , { } , { widths : [ 100 , 200 ] } ) ;
41
-
42
- expect ( ImgixMock . buildSrcSet ) . toHaveBeenCalledWith (
43
- expect . anything ( ) ,
44
- expect . anything ( ) ,
45
- expect . objectContaining ( {
46
- widths : [ 100 , 200 ] ,
47
- } ) ,
48
- ) ;
50
+ expect ( mockImgixClient . buildSrcSet ) . toHaveBeenCalledWith (
51
+ expect . anything ( ) ,
52
+ expect . anything ( ) ,
53
+ expect . objectContaining ( {
54
+ widths : [ 100 , 200 ] ,
55
+ } ) ,
56
+ ) ;
57
+ } ) ;
58
+ it ( 'a custom width tolerance is passed to imgix-core-js' , ( ) => {
59
+ vueImgixClient . buildSrcSet ( 'image.jpg' , { } , { widthTolerance : 0.2 } ) ;
49
60
50
- jest . resetAllMocks ( ) ;
51
- jest . resetModules ( ) ;
61
+ expect ( mockImgixClient . buildSrcSet ) . toHaveBeenCalledWith (
62
+ expect . anything ( ) ,
63
+ expect . anything ( ) ,
64
+ expect . objectContaining ( { widthTolerance : 0.2 } ) ,
65
+ ) ;
66
+ } ) ;
52
67
} ) ;
53
68
} ) ;
0 commit comments