From 3b0786f334643da29aaf3238a97bdff7c11c5601 Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Sat, 14 Sep 2024 18:12:39 +0100 Subject: [PATCH] test: add tests for removing multiple options at once --- .../src/__test__/option-codemods.test.js | 74 ++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/packages/codemods/src/__test__/option-codemods.test.js b/packages/codemods/src/__test__/option-codemods.test.js index d0a03087..bab1658f 100644 --- a/packages/codemods/src/__test__/option-codemods.test.js +++ b/packages/codemods/src/__test__/option-codemods.test.js @@ -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', @@ -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