Skip to content

Commit

Permalink
test: add tests for removing multiple options at once
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Sep 14, 2024
1 parent 3c29acf commit 3b0786f
Showing 1 changed file with 72 additions and 2 deletions.
74 changes: 72 additions & 2 deletions packages/codemods/src/__test__/option-codemods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('codemods operating on options', () => {
'patchOnce',
'any',
'anyOnce',
// all though the src doesn't actually handle these explicitly,
// although the src doesn't actually handle these explicitly,
// these tests ensure that the renaming of these methods to ones that
// do get handled happens first
'getAnyOnce:getOnce',
Expand Down Expand Up @@ -121,7 +121,77 @@ describe('codemods operating on options', () => {
});
});
});
describe('acting on combinations of the 3 options together', () => {});
describe('acting on combinations of the 3 options together', () => {
it('Removes as global option when using Object.assign', () => {
expectCodemodResult(
`Object.assign(fetchMock.config, {sendAsJson: true, overwriteRoutes: true})`,
'',
);
});
it('Removes as global option when using Object.assign alongside other options', () => {
expectCodemodResult(
`Object.assign(fetchMock.config, {sendAsJson: true, overwriteRoutes: true, other: 'value'})`,
`Object.assign(fetchMock.config, {
other: 'value'
})`,
);
});

it(`Removes as option on third parameter of getAnyOnce()`, () => {
expectCodemodResult(
`fetchMock.getAnyOnce(200, {name: 'rio', sendAsJson: true, overwriteRoutes: true})`,
`fetchMock.getOnce("*", 200, {
name: 'rio'
})`,
);
});

it(`Removes third parameter of getAnyOnce() if no other options remain`, () => {
expectCodemodResult(
`fetchMock.getAnyOnce(200, {sendAsJson: true, overwriteRoutes: true})`,
`fetchMock.getOnce("*", 200)`,
);
});
it(`Removes as option on third parameter of any()`, () => {
expectCodemodResult(
`fetchMock.any(200, {name: 'rio', sendAsJson: true, overwriteRoutes: true})`,
`fetchMock.any(200, {
name: 'rio'
})`,
);
});

it(`Removes third parameter of any() if no other options remain`, () => {
expectCodemodResult(
`fetchMock.any(200, {sendAsJson: true, overwriteRoutes: true})`,
`fetchMock.any(200)`,
);
});
it(`Removes as option on first parameter of get()`, () => {
expectCodemodResult(
`fetchMock.get({url: '*', response: 200, sendAsJson: true, overwriteRoutes: true})`,
`fetchMock.get({
url: '*',
response: 200
})`,
);
});
it(`Removes as option on third parameter of get()`, () => {
expectCodemodResult(
`fetchMock.get('*', 200, {name: 'rio', sendAsJson: true, overwriteRoutes: true})`,
`fetchMock.get('*', 200, {
name: 'rio'
})`,
);
});

it(`Removes third parameter of get() if no other options remain`, () => {
expectCodemodResult(
`fetchMock.get('*', 200, {sendAsJson: true, overwriteRoutes: true})`,
`fetchMock.get('*', 200)`,
);
});
});
});
describe('fallbackToNetwork', () => {
// try to replace fallbackToNetwork: always with spyGlobal()... but probably just insert an error / comment that points at the docs
Expand Down

0 comments on commit 3b0786f

Please sign in to comment.