@testing-library/dom#createEvent TypeScript Examples
The following examples show how to use
@testing-library/dom#createEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sagas.test.ts From pybricks-code with MIT License | 6 votes |
test('monitorBeforeInstallPrompt', async () => {
const saga = new AsyncSaga(app);
fireEvent(window, createEvent('beforeinstallprompt', window));
const action = await saga.take();
expect(action).toStrictEqual(appDidReceiveBeforeInstallPrompt());
await saga.end();
});
Example #2
Source File: sagas.test.ts From pybricks-code with MIT License | 6 votes |
test('appShowInstallPrompt', async () => {
const userChoice = {
outcome: <'accepted' | 'dismissed'>'accepted',
platform: 'web',
};
const saga = new AsyncSaga(app);
// mock registration as if service worker was register on app startup
const event = createEvent('beforeinstallprompt', window);
Object.assign(event, <Partial<BeforeInstallPromptEvent>>{
prompt: () => Promise.resolve<void>(undefined),
userChoice: Promise.resolve(userChoice),
});
fireEvent(window, event);
const action = await saga.take();
expect(action).toStrictEqual(appDidReceiveBeforeInstallPrompt());
saga.put(appShowInstallPrompt());
const action2 = await saga.take();
expect(action2).toStrictEqual(appDidResolveInstallPrompt(userChoice));
await saga.end();
});