Skip to content

Commit

Permalink
feat: Add debug option to log matched mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAlbin committed Jul 6, 2022
1 parent b835db4 commit 002eb15
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/withFetchMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ export const withFetchMock = makeDecorator({
skipIfNoParametersOrOptions: false,

wrapper(storyFn, context, { parameters }) {
// If requested, send debug info to the console.
if (fetchMock.called() && parameters && parameters.debug) {
// Construct an object that easy to navigate in the console.
const calls: { [key: string]: MockCall } = {};
fetchMock.calls().forEach((call) => {
calls[call.identifier] = call;
});

// Send the debug data to the console.
console.log({ 'fetch-mock matched these mocks': calls });
}

// Remove any mocks from fetch-mock that may have been defined by other
// stories.
fetchMock.reset();
Expand Down

0 comments on commit 002eb15

Please sign in to comment.