replace msw with setupRequestMockHandlers

Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2021-10-21 14:14:35 +02:00
parent 4f14d881c4
commit 87a7cbdb68
3 changed files with 27 additions and 5 deletions
@@ -14,6 +14,10 @@
* limitations under the License.
*/
/**
* @deprecated use {@link setupRequestMockHandlers} instead which can be called directly with the worker.
* @public
*/
export const msw = {
setupDefaultHandlers: (worker: {
listen: (t: any) => void;
@@ -25,3 +29,18 @@ export const msw = {
afterEach(() => worker.resetHandlers());
},
};
/**
* Sets up handlers for request mocking
* @public
* @param worker - service worker
*/
export function setupRequestMockHandlers(worker: {
listen: (t: any) => void;
close: () => void;
resetHandlers: () => void;
}) {
beforeAll(() => worker.listen({ onUnhandledRequest: 'error' }));
afterAll(() => worker.close());
afterEach(() => worker.resetHandlers());
}