Skip to content

Instantly share code, notes, and snippets.

@ahayes91
Created June 12, 2021 23:34
Show Gist options
  • Save ahayes91/45cd18d2fdb1823eae370540169d9812 to your computer and use it in GitHub Desktop.
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
/**
* 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