Skip to content

Commit

Permalink
feat: codemod resetHistory to clearHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Sep 15, 2024
1 parent fd4ff41 commit 5f1203e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
8 changes: 8 additions & 0 deletions packages/codemods/src/codemods/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`) {
Expand Down
2 changes: 1 addition & 1 deletion packages/codemods/try.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ console.log(
codemod(
`
import fetchMock from 'fetch-mock';
Object.assign(fetchMock.config, {fallbackToNetwork: true})
fetchMock.resetHistory()
`,
jscodeshift,
),
Expand Down

0 comments on commit 5f1203e

Please sign in to comment.