chore: restore expect.any()/expect.anything() (#12820)

This commit is contained in:
Max Schmitt 2022-03-16 21:34:41 +01:00 committed by GitHub
parent bb68875e82
commit e231db1810
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 10 deletions

View file

@ -34,6 +34,8 @@ export declare type Expect = {
extend(arg0: any): void; extend(arg0: any): void;
getState(): expect.MatcherState; getState(): expect.MatcherState;
setState(state: Partial<expect.MatcherState>): void; setState(state: Partial<expect.MatcherState>): void;
any(expectedObject: any): AsymmetricMatcher;
anything(): AsymmetricMatcher;
arrayContaining(sample: Array<unknown>): AsymmetricMatcher; arrayContaining(sample: Array<unknown>): AsymmetricMatcher;
objectContaining(sample: Record<string, unknown>): AsymmetricMatcher; objectContaining(sample: Record<string, unknown>): AsymmetricMatcher;
stringContaining(expected: string): AsymmetricMatcher; stringContaining(expected: string): AsymmetricMatcher;
@ -43,8 +45,6 @@ export declare type Expect = {
* - assertions() * - assertions()
* - extractExpectedAssertionsErrors() * - extractExpectedAssertionsErrors()
* hasAssertions() * hasAssertions()
* - any()
* - anything()
*/ */
}; };

View file

@ -118,17 +118,31 @@ test('should include custom error message with web-first assertions', async ({ r
].join('\n')); ].join('\n'));
}); });
test('should work with default expect prototype functions', async ({ runTSC }) => { test('should work with default expect prototype functions', async ({ runTSC, runInlineTest }) => {
const result = await runTSC({ const spec = `
'a.spec.ts': ` const { test } = pwt;
const { test } = pwt; test('pass', async () => {
const expected = [1, 2, 3, 4, 5, 6]; const expected = [1, 2, 3, 4, 5, 6];
test.expect([4, 1, 6, 7, 3, 5, 2, 5, 4, 6]).toEqual( test.expect([4, 1, 6, 7, 3, 5, 2, 5, 4, 6]).toEqual(
expect.arrayContaining(expected), expect.arrayContaining(expected),
); );
` expect('foo').toEqual(expect.any(String));
}); expect('foo').toEqual(expect.anything());
expect(result.exitCode).toBe(0); });
`;
{
const result = await runTSC({
'a.spec.ts': spec,
});
expect(result.exitCode).toBe(0);
}
{
const result = await runInlineTest({
'a.spec.ts': spec,
});
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
}
}); });
test('should work with default expect matchers', async ({ runTSC }) => { test('should work with default expect matchers', async ({ runTSC }) => {

View file

@ -241,7 +241,8 @@ const TSCONFIG = {
'esModuleInterop': true, 'esModuleInterop': true,
'allowSyntheticDefaultImports': true, 'allowSyntheticDefaultImports': true,
'rootDir': '.', 'rootDir': '.',
'lib': ['esnext', 'dom', 'DOM.Iterable'] 'lib': ['esnext', 'dom', 'DOM.Iterable'],
'noEmit': true,
}, },
'exclude': [ 'exclude': [
'node_modules' 'node_modules'