mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(toHaveProperty): serialize falsy arguments as well (#14232)
This commit is contained in:
parent
79559ae213
commit
fe0afd6b5c
@ -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[] }> {
|
async _expect(customStackTrace: ParsedStackTrace, expression: string, options: Omit<FrameExpectOptions, 'expectedValue'> & { expectedValue?: any }): Promise<{ matches: boolean, received?: any, log?: string[] }> {
|
||||||
return this._frame._wrapApiCall(async () => {
|
return this._frame._wrapApiCall(async () => {
|
||||||
const params: channels.FrameExpectParams = { selector: this._selector, expression, ...options, isNot: !!options.isNot };
|
const params: channels.FrameExpectParams = { selector: this._selector, expression, ...options, isNot: !!options.isNot };
|
||||||
if (options.expectedValue)
|
|
||||||
params.expectedValue = serializeArgument(options.expectedValue);
|
params.expectedValue = serializeArgument(options.expectedValue);
|
||||||
const result = (await this._frame._channel.expect(params));
|
const result = (await this._frame._channel.expect(params));
|
||||||
if (result.received !== undefined)
|
if (result.received !== undefined)
|
||||||
|
@ -133,7 +133,7 @@ test('should support toHaveJSProperty with builtin types', async ({ runInlineTes
|
|||||||
await page.setContent('<div></div>');
|
await page.setContent('<div></div>');
|
||||||
await page.$eval('div', e => e.foo = 'string');
|
await page.$eval('div', e => e.foo = 'string');
|
||||||
const locator = page.locator('div');
|
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 }) => {
|
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.setContent('<div></div>');
|
||||||
await page.$eval('div', e => e.foo = 2021);
|
await page.$eval('div', e => e.foo = 2021);
|
||||||
const locator = page.locator('div');
|
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 }) => {
|
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.setContent('<div></div>');
|
||||||
await page.$eval('div', e => e.foo = false);
|
await page.$eval('div', e => e.foo = false);
|
||||||
const locator = page.locator('div');
|
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 });
|
}, { workers: 1 });
|
||||||
const output = stripAnsi(result.output);
|
const output = stripAnsi(result.output);
|
||||||
expect(result.passed).toBe(3);
|
expect(result.passed).toBe(6);
|
||||||
expect(result.failed).toBe(3);
|
expect(result.failed).toBe(4);
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
expect(output).toContain('Expected: "error"');
|
expect(output).toContain('Expected: "error"');
|
||||||
expect(output).toContain('Received: "string"');
|
expect(output).toContain('Received: "string"');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user