diff --git a/packages/codemods/src/__test__/identifying-fetchmock-instances.test.js b/packages/codemods/src/__test__/identifying-fetchmock-instances.test.js index 0ec271d2..557282e3 100644 --- a/packages/codemods/src/__test__/identifying-fetchmock-instances.test.js +++ b/packages/codemods/src/__test__/identifying-fetchmock-instances.test.js @@ -59,4 +59,5 @@ describe('identifying fetch-mock instances', () => { // sandbox() instances // sandbox() instances used by jest / vitest.mock // identify multiple instances on a page e.g. fetchMock and fm=fetchMock.sandbox() + // identify when a fm instance with lots of chained methods is assigned to a new variable }); diff --git a/packages/codemods/src/codemods/methods.js b/packages/codemods/src/codemods/methods.js index 5d565ff6..540559a7 100644 --- a/packages/codemods/src/codemods/methods.js +++ b/packages/codemods/src/codemods/methods.js @@ -32,6 +32,14 @@ export function simpleMethods(fetchMockVariableName, root, j) { if (method === 'mock') { path.value.callee.property.name = 'route'; } + + if (method === 'mock') { + path.value.callee.property.name = 'route'; + } + + if (method === 'resetHistory') { + path.value.callee.property.name = 'clearHistory'; + } ['get', 'post', 'put', 'delete', 'head', 'patch'].some((httpMethod) => { let prependStar = false; if (method === `${httpMethod}Any`) { diff --git a/packages/codemods/try.js b/packages/codemods/try.js index 0b97c1d9..3cdfdcb0 100644 --- a/packages/codemods/try.js +++ b/packages/codemods/try.js @@ -5,7 +5,7 @@ console.log( codemod( ` import fetchMock from 'fetch-mock'; -Object.assign(fetchMock.config, {fallbackToNetwork: true}) +fetchMock.resetHistory() `, jscodeshift, ),