Skip to content

Commit

Permalink
add expect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam committed Aug 30, 2023
1 parent c93b5af commit fcdf408
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 16 additions & 1 deletion __tests__/fixtures/expect.journey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ declare global {
}
}

// Declare the global matcher in the PW namesapce to be used in tests
// to satisfy the type checker and IDE
declare global {
namespace PlaywrightTest {
interface Matchers<R> {
toBeWithinRange(a: number, b: number): R;
}
}
}

expect.extend({
toBeWithinRange(received, floor, ceiling) {
const pass = received >= floor && received <= ceiling;
Expand All @@ -52,7 +62,7 @@ expect.extend({
},
});

journey('expect journey', ({}) => {
journey('expect journey', ({ page }) => {
step('exports work', () => {
expect(100).toBe(100);
expect([1, 2, 3]).toEqual(expect.arrayContaining([1, 2, 3]));
Expand All @@ -63,4 +73,9 @@ journey('expect journey', ({}) => {
expect(100).toBeWithinRange(90, 120);
expect(101).not.toBeWithinRange(0, 100);
});

step('pw test methods work', async () => {
await expect(page).toHaveURL('about:blank');
await expect(page).toHaveTitle('', { timeout: 100 });
});
});
4 changes: 1 addition & 3 deletions src/core/expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ const expectLib = require('../../dist/bundles/lib/index').expect;
type ExpectLibrary =
typeof import('../../bundles/node_modules/@playwright/test/types/test').expect;

type ModifiedExpect = Omit<ExpectLibrary, 'toMatchSnapshot'>;

export const expect: ModifiedExpect = expectLib;
export const expect: ExpectLibrary = expectLib;

0 comments on commit fcdf408

Please sign in to comment.