mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
add test for app sagas
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2021 The Pybricks Authors
|
||||
|
||||
import { AsyncSaga, delay } from '../../test';
|
||||
import { reload } from '../actions/app';
|
||||
import app from './app';
|
||||
|
||||
test('reload', async () => {
|
||||
const saga = new AsyncSaga(app);
|
||||
|
||||
// mock registration as if service worker was register on app startup
|
||||
const registration: Partial<ServiceWorkerRegistration> = {
|
||||
unregister: jest.fn(),
|
||||
};
|
||||
|
||||
// @ts-expect-error: navigator.serviceWorker is not implemented in JSDOM
|
||||
navigator.serviceWorker = {
|
||||
getRegistrations: jest.fn().mockResolvedValue([registration]),
|
||||
};
|
||||
|
||||
// @ts-expect-error: JSDOM implementation of location.reload() causes error
|
||||
delete window.location;
|
||||
// @ts-expect-error: JSDOM implementation of location.reload() causes error
|
||||
window.location = {
|
||||
reload: jest.fn(),
|
||||
};
|
||||
|
||||
saga.put(reload());
|
||||
|
||||
// yield to allow generators to complete
|
||||
await delay(0);
|
||||
|
||||
expect(registration.unregister).toHaveBeenCalled();
|
||||
expect(location.reload).toHaveBeenCalled();
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
@@ -5,8 +5,6 @@ import { call, takeEvery } from 'redux-saga/effects';
|
||||
import { AppActionType } from '../actions/app';
|
||||
|
||||
function* reload(): Generator {
|
||||
console.log('reload');
|
||||
|
||||
// unregister the service worker so that when the page reloads, it uses
|
||||
// the new version
|
||||
const registrations = (yield call(() =>
|
||||
|
||||
Reference in New Issue
Block a user