Skip to content

Commit

Permalink
test: added tests for resetting method codemods
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Sep 15, 2024
1 parent c272f65 commit fd4ff41
Showing 1 changed file with 85 additions and 2 deletions.
87 changes: 85 additions & 2 deletions packages/codemods/src/__test__/method-codemods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function expectCodemodResult(

describe('codemods operating on methods', () => {
describe('converting mock() to route()', () => {
//TODO Next to the first one in a file leave a comment explaining that they need to use mockGlobal() too
it('single .mock()', () => {
expectCodemodResult(
'fetchMock.mock("blah", 200)',
Expand Down Expand Up @@ -66,6 +65,89 @@ describe('codemods operating on methods', () => {
});
});

describe('converting resetting methods', () => {
it('rewrites restore()', () => {
expectCodemodResult(
'fetchMock.restore()',
`
fetchMock.clearHistory();
fetchMock.removeRoutes({
includeFallback: true,
});
fetchMock.unmockGlobal();
`,
);
});
it('rewrites restore() with {sticky: true}', () => {
expectCodemodResult(
'fetchMock.restore({sticky: true})',
`
fetchMock.clearHistory();
fetchMock.removeRoutes({
includeSticky: true,
includeFallback: true,
});
fetchMock.unmockGlobal();
`,
);
});
it('rewrites reset()', () => {
expectCodemodResult(
'fetchMock.reset()',
`
fetchMock.clearHistory();
fetchMock.removeRoutes({
includeFallback: true,
});
fetchMock.unmockGlobal();
`,
);
});
it('rewrites reset() with {sticky: true}', () => {
expectCodemodResult(
'fetchMock.reset({sticky: true})',
`
fetchMock.clearHistory();
fetchMock.removeRoutes({
includeSticky: true,
includeFallback: true,
});
fetchMock.unmockGlobal();
`,
);
});

it('rewrites resetBehavior()', () => {
expectCodemodResult(
'fetchMock.resetBehavior()',
`
fetchMock.removeRoutes({
includeFallback: true,
});
fetchMock.unmockGlobal();
`,
);
});
it('rewrites resetBehavior() with {sticky: true}', () => {
expectCodemodResult(
'fetchMock.resetBehavior({sticky: true})',
`
fetchMock.removeRoutes({
includeSticky: true,
includeFallback: true,
});
fetchMock.unmockGlobal();
`,
);
});
it('rewrites resetHistory()', () => {
expectCodemodResult(
'fetchMock.resetHistory()',
'fetchMock.clearHistory()',
);
});
});

describe('converting lastUrl()', () => {
it('single .lastUrl()', () => {
expectCodemodResult(
Expand Down Expand Up @@ -179,6 +261,7 @@ describe('codemods operating on methods', () => {
});

// .sandbox() => .fetchHandler(and maybe a comment about.createInstance())
// restore() / reset()... once I've decided how to implement these

// lastCall() => try to change uses of this to expect a callLog, but probably just insert a commemnt / error
// calls() => add error
});

0 comments on commit fd4ff41

Please sign in to comment.