Skip to content

Commit

Permalink
rewrite spy fixtures with expect.poll
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi committed Jan 16, 2025
1 parent 5b3ef5e commit 62e8a8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 31 deletions.
49 changes: 19 additions & 30 deletions tests/e2e/fixtures/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const test = base.extend<{ page: Page }, BaseScopeWorker>({
const defaultMessage = (
thisType: ExpectMatcherState,
assertionName: string,
pass: boolean,
_pass: boolean,
expected: unknown,
matcherResult?: { actual: unknown },
) => {
Expand All @@ -89,7 +89,7 @@ const defaultMessage = (
undefined,
{ isNot: thisType.isNot },
);
const expectedPart = `Expected:${pass ? '' : ' not '}${thisType.utils.printExpected(expected)}`;
const expectedPart = `Expected: ${thisType.isNot ? 'not ' : ''}${thisType.utils.printExpected(expected)}`;
const receivedPart = matcherResult
? `Received: ${thisType.utils.printReceived(matcherResult.actual)}`
: '';
Expand Down Expand Up @@ -135,19 +135,13 @@ export const expect = test.expect.extend({
let pass: boolean;
let result: { actual: number } | undefined;

let remainingTime = timeout;
do {
try {
test.expect(fn.callCount).toBe(expected);
pass = true;
break;
} catch {
result = { actual: fn.callCount };
pass = false;
remainingTime -= 500;
await sleep(500);
}
} while (remainingTime > 0);
try {
await test.expect.poll(() => fn.callCount, { timeout }).toBe(expected);
pass = true;
} catch {
result = { actual: fn.callCount };
pass = false;
}

return {
name,
Expand All @@ -168,21 +162,16 @@ export const expect = test.expect.extend({
let pass: boolean;
let result: { actual: unknown } | undefined;

let remainingTime = timeout;
do {
try {
// we only support matching first argument of last call
const lastCallArg = fn.calls[fn.calls.length - 1][0];
test.expect(lastCallArg).toMatchObject(expected);
pass = true;
break;
} catch {
result = { actual: fn.calls[fn.calls.length - 1]?.[0] };
pass = false;
remainingTime -= 500;
await sleep(500);
}
} while (remainingTime > 0);
try {
// we only support matching first argument of last call
await test.expect
.poll(() => fn.calls[fn.calls.length - 1][0], { timeout })
.toMatchObject(expected);
pass = true;
} catch {
result = { actual: fn.calls[fn.calls.length - 1]?.[0] };
pass = false;
}

return {
name,
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/reconnectAutoKeyTestWallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test('Reconnect to test wallet with automatic key addition', async ({

await test.step('asks for key-add consent', async () => {
await connectButton.click();
expect(
await expect(
popup.getByTestId('connect-wallet-auto-key-consent'),
).toBeVisible();
await popup
Expand Down

0 comments on commit 62e8a8c

Please sign in to comment.