mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
chore(): sync with main
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { toHaveReceivedEvent } from './toHaveReceivedEvent';
|
||||
import { toHaveReceivedEventDetail } from './toHaveReceivedEventDetail';
|
||||
import { toHaveReceivedEventTimes } from './toHaveReceivedEventTimes';
|
||||
|
||||
export const matchers = {
|
||||
toHaveReceivedEvent,
|
||||
toHaveReceivedEventDetail,
|
||||
toHaveReceivedEventTimes,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import type { EventSpy } from '../page/event-spy';
|
||||
|
||||
export function toHaveReceivedEventTimes(eventSpy: EventSpy, count: number) {
|
||||
if (!eventSpy) {
|
||||
return {
|
||||
message: () => `toHaveReceivedEventTimes event spy is null`,
|
||||
pass: false,
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof (eventSpy as any).then === 'function') {
|
||||
return {
|
||||
message: () =>
|
||||
`expected spy to have received event, but it was not resolved (did you forget an await operator?).`,
|
||||
pass: false,
|
||||
};
|
||||
}
|
||||
|
||||
if (!eventSpy.eventName) {
|
||||
return {
|
||||
message: () => `toHaveReceivedEventTimes did not receive an event spy`,
|
||||
pass: false,
|
||||
};
|
||||
}
|
||||
|
||||
const pass = eventSpy.length === count;
|
||||
|
||||
return {
|
||||
message: () =>
|
||||
`expected event "${eventSpy.eventName}" to have been called ${count} times, but it was called ${eventSpy.events.length} times`,
|
||||
pass: pass,
|
||||
};
|
||||
}
|
||||
@@ -8,6 +8,11 @@ interface CustomMatchers<R = unknown> {
|
||||
* @param eventDetail The expected detail of the event.
|
||||
*/
|
||||
toHaveReceivedEventDetail(eventDetail: any): R;
|
||||
|
||||
/**
|
||||
* Will check how many times the event has been received.
|
||||
*/
|
||||
toHaveReceivedEventTimes(count: number): R;
|
||||
}
|
||||
|
||||
declare namespace PlaywrightTest {
|
||||
|
||||
Reference in New Issue
Block a user