test: Implements intervals config tests

This commit is contained in:
Hansanto 2024-03-28 10:34:43 +01:00
parent f3ac04ea8a
commit d882720c7b

View file

@ -263,32 +263,38 @@ test('should give priority to timeout parameter over timeout in config file', as
test('should respect intervals in config file when intervals parameter is not passed', async ({ runInlineTest }) => { test('should respect intervals in config file when intervals parameter is not passed', async ({ runInlineTest }) => {
const result = await runInlineTest({ const result = await runInlineTest({
'playwright.config.js': `module.exports = { expect: { toPass: { intervals: [100, 200] } } }`, 'playwright.config.js': `module.exports = { expect: { toPass: { timeout: 2000, intervals: [100, 1000] } } }`,
'a.spec.ts': ` 'a.spec.ts': `
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
test('should fail', async () => { test('should fail', async () => {
let attempt = 0;
await test.expect(() => { await test.expect(() => {
expect(1).toBe(2); expect(++attempt).toBe(-1);
}).toPass(); }).toPass();
}); });
` `
}); });
expect(result.exitCode).toBe('TODO'); expect(result.exitCode).toBe(1);
// TODO expect(result.output).toContain('Error: expect(received).toBe(expected) // Object.is equality');
expect(result.output).toContain('Expected: -1');
expect(result.output).toContain('Received: 3');
}); });
test('should give priority to intervals parameter over intervals in config file', async ({ runInlineTest }) => { test('should give priority to intervals parameter over intervals in config file', async ({ runInlineTest }) => {
const result = await runInlineTest({ const result = await runInlineTest({
'playwright.config.js': `module.exports = { expect: { toPass: { intervals: [100, 200] } } }`, 'playwright.config.js': `module.exports = { expect: { toPass: { timeout: 2000, intervals: [100] } } }`,
'a.spec.ts': ` 'a.spec.ts': `
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
test('should fail', async () => { test('should fail', async () => {
let attempt = 0;
await test.expect(() => { await test.expect(() => {
expect(1).toBe(2); expect(++attempt).toBe(-1);
}).toPass({ intervals: [500] }); }).toPass({ intervals: [100, 1000] });
}); });
` `
}); });
expect(result.exitCode).toBe('TODO'); expect(result.exitCode).toBe(1);
// TODO expect(result.output).toContain('Error: expect(received).toBe(expected) // Object.is equality');
expect(result.output).toContain('Expected: -1');
expect(result.output).toContain('Received: 3');
}); });