fix(toHaveProperty): serialize falsy arguments as well (#14232)

This commit is contained in:
Pavel Feldman 2022-05-17 14:44:12 -07:00 committed by GitHub
parent 79559ae213
commit fe0afd6b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 7 deletions

View File

@ -276,7 +276,6 @@ export class Locator implements api.Locator {
async _expect(customStackTrace: ParsedStackTrace, expression: string, options: Omit<FrameExpectOptions, 'expectedValue'> & { expectedValue?: any }): Promise<{ matches: boolean, received?: any, log?: string[] }> {
return this._frame._wrapApiCall(async () => {
const params: channels.FrameExpectParams = { selector: this._selector, expression, ...options, isNot: !!options.isNot };
if (options.expectedValue)
params.expectedValue = serializeArgument(options.expectedValue);
const result = (await this._frame._channel.expect(params));
if (result.received !== undefined)

View File

@ -133,7 +133,7 @@ test('should support toHaveJSProperty with builtin types', async ({ runInlineTes
await page.setContent('<div></div>');
await page.$eval('div', e => e.foo = 'string');
const locator = page.locator('div');
await expect(locator).toHaveJSProperty('foo', 'error', {timeout: 1000});
await expect(locator).toHaveJSProperty('foo', 'error', {timeout: 200});
});
test('pass number', async ({ page }) => {
@ -147,7 +147,7 @@ test('should support toHaveJSProperty with builtin types', async ({ runInlineTes
await page.setContent('<div></div>');
await page.$eval('div', e => e.foo = 2021);
const locator = page.locator('div');
await expect(locator).toHaveJSProperty('foo', 1, {timeout: 1000});
await expect(locator).toHaveJSProperty('foo', 1, {timeout: 200});
});
test('pass boolean', async ({ page }) => {
@ -161,13 +161,40 @@ test('should support toHaveJSProperty with builtin types', async ({ runInlineTes
await page.setContent('<div></div>');
await page.$eval('div', e => e.foo = false);
const locator = page.locator('div');
await expect(locator).toHaveJSProperty('foo', true, {timeout: 1000});
await expect(locator).toHaveJSProperty('foo', true, {timeout: 200});
});
test('pass boolean 2', async ({ page }) => {
await page.setContent('<div></div>');
await page.$eval('div', e => e.foo = false);
const locator = page.locator('div');
await expect(locator).toHaveJSProperty('foo', false);
});
test('fail boolean 2', async ({ page }) => {
await page.setContent('<div></div>');
await page.$eval('div', e => e.foo = false);
const locator = page.locator('div');
await expect(locator).toHaveJSProperty('foo', true, {timeout: 200});
});
test('pass undefined', async ({ page }) => {
await page.setContent('<div></div>');
const locator = page.locator('div');
await expect(locator).toHaveJSProperty('foo', undefined);
});
test('pass null', async ({ page }) => {
await page.setContent('<div></div>');
await page.$eval('div', e => e.foo = null);
const locator = page.locator('div');
await expect(locator).toHaveJSProperty('foo', null);
});
`,
}, { workers: 1 });
const output = stripAnsi(result.output);
expect(result.passed).toBe(3);
expect(result.failed).toBe(3);
expect(result.passed).toBe(6);
expect(result.failed).toBe(4);
expect(result.exitCode).toBe(1);
expect(output).toContain('Expected: "error"');
expect(output).toContain('Received: "string"');