Created
June 12, 2021 23:34
-
-
Save ahayes91/45cd18d2fdb1823eae370540169d9812 to your computer and use it in GitHub Desktop.
Reusable function for putting a spy on all requests received by a Mock Service Worker server during a test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Function creating a spy on requests handled by MSW | |
* @param server - MSW server instance | |
* @returns {jest.Mock} - spy on requests handled by MSW | |
*/ | |
export const createRequestSpy = server => { | |
const requestSpy = jest.fn(); // eslint-disable-line no-undef | |
server.on('request:end', requestSpy); | |
return requestSpy; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment