Skip to content

Commit

Permalink
fix the test
Browse files Browse the repository at this point in the history
  • Loading branch information
bakamitai456 committed Jun 16, 2023
1 parent 5e58009 commit acb42b0
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/jest-snapshot/src/__tests__/throwMatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,26 @@ describe('throw matcher from promise', () => {
});

describe('toThrowErrorMatchingNamedSnapshot', () => {
const mockedNamedMatch = jest.fn(() => ({
actual: 'coconut',
expected: 'coconut',
key: 'snapshot name 1',
}));

const mockedNamedContext = {
snapshotState: {match: mockedNamedMatch},
} as unknown as Context;

it('can take error', () => {
toThrowErrorMatchingNamedSnapshot.call(
mockedContext,
mockedNamedContext,
new Error('coco'),
'snapshot name',
true,
);

expect(mockedMatch).toHaveBeenCalledTimes(1);
expect(mockedMatch).toHaveBeenCalledWith(
expect(mockedNamedMatch).toHaveBeenCalledTimes(1);
expect(mockedNamedMatch).toHaveBeenCalledWith(
expect.objectContaining({received: 'coco', testName: 'snapshot name'}),
);
});
Expand All @@ -110,14 +120,14 @@ describe('throw matcher from promise', () => {
class CustomError extends Error {}

toThrowErrorMatchingNamedSnapshot.call(
mockedContext,
mockedNamedContext,
new CustomError('nut'),
'snapshot name',
true,
);

expect(mockedMatch).toHaveBeenCalledTimes(1);
expect(mockedMatch).toHaveBeenCalledWith(
expect(mockedNamedMatch).toHaveBeenCalledTimes(1);
expect(mockedNamedMatch).toHaveBeenCalledWith(
expect.objectContaining({received: 'nut', testName: 'snapshot name'}),
);
});
Expand Down

0 comments on commit acb42b0

Please sign in to comment.