diff --git a/packages/codemods/src/__test__/method-codemods.test.js b/packages/codemods/src/__test__/method-codemods.test.js index fba45ae0..7d0175d3 100644 --- a/packages/codemods/src/__test__/method-codemods.test.js +++ b/packages/codemods/src/__test__/method-codemods.test.js @@ -144,14 +144,21 @@ fetchMock.unmockGlobal();`, }); }); - describe('converting lastCall()', () => { - it('single .lastUrl()', () => { + describe('warning about CallLog', () => { + it('lastCall()', () => { expectCodemodResult( 'fetchMock.lastCall()', `throw new Error("lastCall() now returns a CallLog object instead of an array. Refer to the documentation") fetchMock.lastCall()`, ); }); + it('calls()', () => { + expectCodemodResult( + 'fetchMock.calls()', + `throw new Error("calls() now returns an array of CallLog objects instead of an array of arrays. Refer to the documentation") +fetchMock.calls()`, + ); + }); }); describe('converting lastOptions()', () => { @@ -244,6 +251,4 @@ fetchMock.lastCall()`, }); // .sandbox() => .fetchHandler(and maybe a comment about.createInstance()) - // lastCall() => try to change uses of this to expect a callLog, but probably just insert a commemnt / error - // calls() => add error }); diff --git a/packages/codemods/src/codemods/methods.js b/packages/codemods/src/codemods/methods.js index 14926ee2..b52695f6 100644 --- a/packages/codemods/src/codemods/methods.js +++ b/packages/codemods/src/codemods/methods.js @@ -136,4 +136,25 @@ fetchMock.unmockGlobal(); .find(j.ThrowStatement) .get().value, ); + + root + .find(j.CallExpression, { + callee: { + object: { + type: 'Identifier', + name: fetchMockVariableName, + }, + property: { + name: 'calls', + }, + }, + }) + .closest(j.ExpressionStatement) + .insertBefore( + j( + 'throw new Error("calls() now returns an array of CallLog objects instead of an array of arrays. Refer to the documentation")', + ) + .find(j.ThrowStatement) + .get().value, + ); }