Skip to content
Merged
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
4 changes: 4 additions & 0 deletions packages/playwright/src/matchers/expectLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ class ArrayContaining extends AsymmetricMatcher<Array<unknown>> {
}

class ArrayOf extends AsymmetricMatcher<unknown> {
constructor(sample: unknown, inverse = false) {
super(typeof sample === 'function' ? new Any(sample) : sample, inverse);
}

asymmetricMatch(other: unknown) {
const matcherContext = this.getMatcherContext();
const result =
Expand Down
22 changes: 22 additions & 0 deletions tests/playwright-test/expect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,28 @@ test('should support arrayOf', async ({ runInlineTest }) => {
expect(result.output).toContain('ArrayOf Any<Number>');
});

test('should support arrayOf with constructor', async ({ runInlineTest }) => {
const result = await runInlineTest({
'expect-test.spec.ts': `
import { test, expect } from '@playwright/test';
class Example {}
test('pass', () => {
expect(['a', 'b', 'c']).toEqual(expect.arrayOf(String));
expect([1, 2, 3]).toEqual(expect.arrayOf(Number));
expect([new Example(), new Example()]).toEqual(expect.arrayOf(Example));
expect(['a', 1]).toEqual(expect.not.arrayOf(String));
});
test('fail', () => {
expect(['a', 'b', 3]).toEqual(expect.arrayOf(String));
});
`
});
expect(result.exitCode).toBe(1);
expect(result.passed).toBe(1);
expect(result.failed).toBe(1);
expect(result.output).toContain('ArrayOf Any<String>');
});

test('should account for undefined matcherResult', async ({ runInlineTest }) => {
const result = await runInlineTest({
'example.spec.ts': `
Expand Down
Loading