Skip to content

Commit

Permalink
test(unit): min/max srcset widths for buildSrcSet
Browse files Browse the repository at this point in the history
  • Loading branch information
frederickfogerty committed May 1, 2020
1 parent 2e38068 commit 833ad12
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/unit/build-src-set.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import {
buildImgixClient,
IVueImgixClient,
Expand All @@ -19,4 +20,34 @@ describe('buildSrcSet', () => {
expect(firstSrcSet[0]).toMatch(/w=[0-9]/);
expect(firstSrcSet[1]).toMatch(/^[0-9]+w$/);
});

it('custom widths are passed to imgix-core-js', () => {
jest.resetModules();
jest.mock('imgix-core-js');
const { buildImgixClient } = require('@/plugins/vue-imgix/');
const ImgixClient = require('imgix-core-js');
const ImgixMock = {
settings: {},
buildSrcSet: jest.fn(),
buildURL: jest.fn(),
};
ImgixClient.mockImplementation(() => ImgixMock);

const client = buildImgixClient({
domain: 'testing.imgix.net',
});

client.buildSrcSet('image.jpg', {}, { widths: [100, 200] });

expect(ImgixMock.buildSrcSet).toHaveBeenCalledWith(
expect.anything(),
expect.anything(),
expect.objectContaining({
widths: [100, 200],
}),
);

jest.resetAllMocks();
jest.resetModules();
});
});

0 comments on commit 833ad12

Please sign in to comment.