Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly order arguments in Jest diff util (#1245)
Some custom matchers like `@testing-library/jest-dom` use `this.utils.diff` for the output. In Jest the order of arguments in that util is "expected", then "received", so we're fixing the order of those arguments here to match Jest's implementation.
- Loading branch information
Showing
2 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
describe('jest-matcher-utils', () => { | ||
expect.extend({ | ||
toBeJestEqual(received: any, expected: any) { | ||
return { | ||
message: () => this.utils.diff(expected, received), | ||
pass: received === expected, | ||
} | ||
}, | ||
}) | ||
|
||
it('diff', () => { | ||
expect(() => { | ||
// @ts-expect-error "toBeJestEqual" is a custom matcher we just created | ||
expect('a').toBeJestEqual('b') | ||
}).toThrowError(/Expected.*"b".*Received.*"a"/ms) | ||
}) | ||
}) |