Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Array matching #15091

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
- `[jest-config]` Allow `reporters` in project config ([#14768](https://github.com/jestjs/jest/pull/14768))
- `[jest-config]` Allow Node16/NodeNext/Bundler `moduleResolution` in project's tsconfig ([#14739](https://github.com/jestjs/jest/pull/14739))
- `[jest-each]` Allow `$keypath` templates with `null` or `undefined` values ([#14831](https://github.com/jestjs/jest/pull/14831))
- `[jest-expect]` Fix matching of `Array` when instances are created in a new context. ([#15091](https://github.com/jestjs/jest/pull/15091))
- `[@jest/expect-utils]` Fix comparison of `DataView` ([#14408](https://github.com/jestjs/jest/pull/14408))
- `[@jest/expect-utils]` [**BREAKING**] exclude non-enumerable in object matching ([#14670](https://github.com/jestjs/jest/pull/14670))
- `[@jest/expect-utils]` Fix comparison of `URL` ([#14672](https://github.com/jestjs/jest/pull/14672))
Expand Down
2 changes: 2 additions & 0 deletions packages/expect/src/__tests__/asymmetricMatchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
*/

import {runInNewContext} from 'node:vm';
import jestExpect from '../';
import {
any,
Expand Down Expand Up @@ -51,6 +52,7 @@ test('Any.asymmetricMatch() on primitive wrapper classes', () => {
any(Boolean).asymmetricMatch(new Boolean(true)),
any(BigInt).asymmetricMatch(Object(1n)),
any(Symbol).asymmetricMatch(Object(Symbol())),
any(Array).asymmetricMatch(runInNewContext('[];')),
/* eslint-enable */
]) {
jestExpect(test).toBe(true);
Expand Down
8 changes: 8 additions & 0 deletions packages/expect/src/asymmetricMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ class Any extends AsymmetricMatcher<any> {
return typeof other == 'object';
}

if (this.sample == Array) {
return Array.isArray(other);
}

return other instanceof this.sample;
}

Expand Down Expand Up @@ -164,6 +168,10 @@ class Any extends AsymmetricMatcher<any> {
return 'boolean';
}

if (Array.isArray(this.sample)) {
return 'array';
}

return fnNameFor(this.sample);
}

Expand Down
Loading