Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: diff output is incorrectly when using expect.any (#1197)
- Loading branch information
Showing
4 changed files
with
129 additions
and
40 deletions.
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
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,49 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { replaceAsymmetricMatcher } from '../../../packages/vitest/src/runtime/error' | ||
|
||
describe('replace asymmetric matcher', () => { | ||
const expectReplaceAsymmetricMatcher = (actual: any, expected: any) => { | ||
const replaced = replaceAsymmetricMatcher(actual, expected) | ||
expect(replaced.replacedActual).toEqual(replaced.replacedExpected) | ||
} | ||
it('should work when various types are passed in', () => { | ||
expectReplaceAsymmetricMatcher(null, null) | ||
expectReplaceAsymmetricMatcher(undefined, undefined) | ||
expectReplaceAsymmetricMatcher({}, {}) | ||
expectReplaceAsymmetricMatcher([1, 2], [1, 2]) | ||
expectReplaceAsymmetricMatcher({}, expect.any(Object)) | ||
expectReplaceAsymmetricMatcher(() => {}, expect.any(Function)) | ||
expectReplaceAsymmetricMatcher(Promise, expect.any(Function)) | ||
expectReplaceAsymmetricMatcher(false, expect.any(Boolean)) | ||
expectReplaceAsymmetricMatcher([1, 2], [1, expect.any(Number)]) | ||
expectReplaceAsymmetricMatcher(false, expect.anything()) | ||
expectReplaceAsymmetricMatcher({}, expect.anything()) | ||
expectReplaceAsymmetricMatcher(Symbol, expect.anything()) | ||
expectReplaceAsymmetricMatcher(Promise, expect.anything()) | ||
expectReplaceAsymmetricMatcher(new Map([['a', 1]]), expect.anything()) | ||
expectReplaceAsymmetricMatcher(new Set([1, 2]), expect.anything()) | ||
expectReplaceAsymmetricMatcher(new ArrayBuffer(8), expect.anything()) | ||
expectReplaceAsymmetricMatcher([1, 2], [1, expect.anything()]) | ||
expectReplaceAsymmetricMatcher({ | ||
str: 'a', | ||
arr: [1, 2], | ||
}, { | ||
str: expect.any(String), | ||
arr: expect.anything(), | ||
}) | ||
expectReplaceAsymmetricMatcher({ | ||
str: expect.any(String), | ||
arr: expect.anything(), | ||
}, { | ||
str: expect.any(String), | ||
arr: expect.anything(), | ||
}) | ||
expectReplaceAsymmetricMatcher({ | ||
str: 'a', | ||
arr: [1, 2], | ||
}, { | ||
str: expect.any(String), | ||
arr: [1, expect.anything()], | ||
}) | ||
}) | ||
}) |