Skip to content

Commit 2194e44

Browse files
committed
refactor(test): remove sinon / mocha
1 parent f53d6c9 commit 2194e44

File tree

8 files changed

+72
-1122
lines changed

8 files changed

+72
-1122
lines changed

package-lock.json

Lines changed: 0 additions & 1034 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@
5252
"gts": "^3.1.0",
5353
"jest": "^27.5.1",
5454
"jsdom": "^19.0.0",
55-
"mocha": "^9.1.3",
5655
"nock": "^13.2.0",
5756
"react": "^17.0.2",
5857
"react-dom": "^17.0.2",
59-
"sinon": "^12.0.1",
6058
"ts-jest": "^27.1.4",
6159
"ts-node": "^10.4.0",
6260
"typescript": "^4.0.3"

src/lib/transport/axios.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function axiosTransport(): Transport {
2626
});
2727
return response;
2828
})
29+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2930
.catch((err: any) => {
3031
if (err.isAxiosError)
3132
errorHandler<T>({

test/client/autosuggest.spec.ts

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { spy, SinonSpy } from 'sinon';
21
import { Chance } from 'chance';
32
import {
43
ApiClientConfiguration,
54
ApiVersion,
65
AutosuggestClient,
76
AutosuggestInputType,
87
HEADERS,
9-
Transport,
108
} from '../../src';
119
import { generateAutosuggestSuggestion, generateCoordinate } from '../fixtures';
1210

@@ -17,25 +15,22 @@ describe('Autosuggest Client', () => {
1715
let apiVersion: ApiVersion;
1816
let host: string;
1917
let config: ApiClientConfiguration;
20-
let transportSpy: SinonSpy;
21-
let transport: Transport;
18+
let transportSpy: jest.Mock<Promise<{ status: number; body: never }>, never>;
2219
let client: AutosuggestClient;
2320

2421
beforeEach(() => {
2522
apiKey = CHANCE.string({ length: 8 });
2623
apiVersion = ApiVersion.Version1;
2724
host = CHANCE.url({ path: '' });
2825
config = { host, apiVersion, headers: {} };
29-
transportSpy = spy();
30-
transport = async (...args) => {
31-
transportSpy(...args);
32-
return {
26+
transportSpy = jest.fn(
27+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
28+
async (..._args: never): Promise<{ status: number; body: never }> => ({
3329
status: 200,
34-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
35-
body: {} as any,
36-
};
37-
};
38-
client = AutosuggestClient.init(apiKey, config, transport);
30+
body: {} as never,
31+
})
32+
);
33+
client = AutosuggestClient.init(apiKey, config, transportSpy);
3934
});
4035

4136
it('should instantiate an Autosuggest Client instance', () => {
@@ -146,7 +141,7 @@ describe('Autosuggest Client', () => {
146141
language,
147142
preferLand,
148143
});
149-
expect(transportSpy.calledOnceWith(transportArguments)).toEqual(true);
144+
expect(transportSpy).toHaveBeenNthCalledWith(1, transportArguments);
150145
});
151146
it('should call /autosuggest with voice input type', async () => {
152147
const input = `${CHANCE.word()}.${CHANCE.word()}.${CHANCE.letter()}`;
@@ -175,7 +170,7 @@ describe('Autosuggest Client', () => {
175170
inputType,
176171
language,
177172
});
178-
expect(transportSpy.calledOnceWith(transportArguments)).toEqual(true);
173+
expect(transportSpy).toHaveBeenNthCalledWith(1, transportArguments);
179174
});
180175
it('should throw error when no language provided with voice input type', async () => {
181176
const input = `${CHANCE.word()}.${CHANCE.word()}.${CHANCE.letter()}`;
@@ -195,7 +190,7 @@ describe('Autosuggest Client', () => {
195190
'You must provide language when using a speech input type'
196191
);
197192
} finally {
198-
expect(transportSpy.notCalled).toEqual(true);
193+
expect(transportSpy).not.toHaveBeenCalled();
199194
}
200195
});
201196
it('should throw error if no options provided', async () => {
@@ -205,7 +200,7 @@ describe('Autosuggest Client', () => {
205200
} catch (err) {
206201
expect(err.message).toEqual('You must provide at least options.input');
207202
} finally {
208-
expect(transportSpy.notCalled).toEqual(true);
203+
expect(transportSpy).not.toHaveBeenCalled();
209204
}
210205
});
211206
it('should throw error if input is empty', async () => {
@@ -216,7 +211,7 @@ describe('Autosuggest Client', () => {
216211
} catch (err) {
217212
expect(err.message).toEqual('You must specify an input value');
218213
} finally {
219-
expect(transportSpy.notCalled).toEqual(true);
214+
expect(transportSpy).not.toHaveBeenCalled();
220215
}
221216
});
222217
it('should throw error if clipToBoundingBox has southwest lat > northeast lat', async () => {
@@ -233,7 +228,7 @@ describe('Autosuggest Client', () => {
233228
'Southwest lat must be less than or equal to northeast lat and southwest lng must be less than or equal to northeast lng'
234229
);
235230
} finally {
236-
expect(transportSpy.notCalled).toEqual(true);
231+
expect(transportSpy).not.toHaveBeenCalled();
237232
}
238233
});
239234
it('should throw error if clipToBoundingBox has southwest lng > northeast lng', async () => {
@@ -250,7 +245,7 @@ describe('Autosuggest Client', () => {
250245
'Southwest lat must be less than or equal to northeast lat and southwest lng must be less than or equal to northeast lng'
251246
);
252247
} finally {
253-
expect(transportSpy.notCalled).toEqual(true);
248+
expect(transportSpy).not.toHaveBeenCalled();
254249
}
255250
});
256251
it('should throw error if clipToCountry has incorrect value', async () => {
@@ -268,7 +263,7 @@ describe('Autosuggest Client', () => {
268263
'Invalid clip to country. All values must be an ISO 3166-1 alpha-2 country code'
269264
);
270265
} finally {
271-
expect(transportSpy.notCalled).toEqual(true);
266+
expect(transportSpy).not.toHaveBeenCalled();
272267
}
273268
});
274269
it('should throw error if clipToPolygon has less than 4 entries', async () => {
@@ -287,7 +282,7 @@ describe('Autosuggest Client', () => {
287282
'Invalid clip to polygon value. Array must contain at least 4 coordinates and no more than 25'
288283
);
289284
} finally {
290-
expect(transportSpy.notCalled).toEqual(true);
285+
expect(transportSpy).not.toHaveBeenCalled();
291286
}
292287
});
293288
it('should throw error if clipToPolygon is not closed', async () => {
@@ -306,7 +301,7 @@ describe('Autosuggest Client', () => {
306301
'Invalid clip to polygon value. The polygon bounds must be closed.'
307302
);
308303
} finally {
309-
expect(transportSpy.notCalled).toEqual(true);
304+
expect(transportSpy).not.toHaveBeenCalled();
310305
}
311306
});
312307
it('should throw error if inputType is not valid', async () => {
@@ -320,7 +315,7 @@ describe('Autosuggest Client', () => {
320315
'Invalid input type provided. Must provide a valid input type.'
321316
);
322317
} finally {
323-
expect(transportSpy.notCalled).toEqual(true);
318+
expect(transportSpy).not.toHaveBeenCalled();
324319
}
325320
});
326321
const voiceInputTypes = [
@@ -339,7 +334,7 @@ describe('Autosuggest Client', () => {
339334
'You must provide language when using a speech input type'
340335
);
341336
} finally {
342-
expect(transportSpy.notCalled).toEqual(true);
337+
expect(transportSpy).not.toHaveBeenCalled();
343338
}
344339
});
345340
});
@@ -354,7 +349,7 @@ describe('Autosuggest Client', () => {
354349
'Invalid language code. It must be an ISO-639-1 2 letter code.'
355350
);
356351
} finally {
357-
expect(transportSpy.notCalled).toEqual(true);
352+
expect(transportSpy).not.toHaveBeenCalled();
358353
}
359354
});
360355
it('should call /autosuggest-selection with selected suggestion', async () => {
@@ -375,8 +370,7 @@ describe('Autosuggest Client', () => {
375370

376371
const actualOnSelected = await client.onSelected(selected);
377372
expect(actualOnSelected).toEqual(undefined);
378-
const actual = transportSpy.calledOnceWith(transportArguments);
379-
expect(actual).toEqual(true);
373+
expect(transportSpy).toHaveBeenNthCalledWith(1, transportArguments);
380374
});
381375
describe('should call /autosuggest-selection with initial request options override', () => {
382376
const input = `${CHANCE.word()}.${CHANCE.word()}.${CHANCE.letter()}`;
@@ -451,9 +445,9 @@ describe('Autosuggest Client', () => {
451445
preferLand,
452446
});
453447
expect(actualOnSelected).toEqual(undefined);
454-
const actual = transportSpy.calledOnceWith(transportArguments);
455-
expect(actual).toEqual(true);
448+
expect(transportSpy).toHaveBeenNthCalledWith(1, transportArguments);
456449
});
450+
457451
it('voice input type', async () => {
458452
const inputType = AutosuggestInputType.GenericVoice;
459453
transportArguments.body['input-type'] = inputType;
@@ -473,8 +467,7 @@ describe('Autosuggest Client', () => {
473467
preferLand,
474468
});
475469
expect(actualOnSelected).toEqual(undefined);
476-
const actual = transportSpy.calledOnceWith(transportArguments);
477-
expect(actual).toEqual(true);
470+
expect(transportSpy).toHaveBeenNthCalledWith(1, transportArguments);
478471
});
479472
});
480473
});

test/client/available-languages.spec.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { spy, SinonSpy } from 'sinon';
21
import { Chance } from 'chance';
32
import {
43
ApiClientConfiguration,
54
ApiVersion,
65
AvailableLanguagesClient,
76
HEADERS,
8-
Transport,
97
} from '../../src';
108

119
const CHANCE = new Chance();
@@ -15,22 +13,22 @@ describe('Available Languages Client', () => {
1513
let apiVersion: ApiVersion;
1614
let host: string;
1715
let config: ApiClientConfiguration;
18-
let transportSpy: SinonSpy;
19-
let transport: Transport;
16+
let transportSpy: jest.Mock<Promise<{ status: number; body: never }>, never>;
2017
let client: AvailableLanguagesClient;
2118

2219
beforeEach(() => {
2320
apiKey = CHANCE.string({ length: 8 });
2421
apiVersion = ApiVersion.Version1;
2522
host = CHANCE.url({ path: '' });
2623
config = { host, apiVersion };
27-
transportSpy = spy();
28-
transport = async (...args) => {
29-
transportSpy(...args);
30-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
31-
return { status: 200, body: {} as any };
32-
};
33-
client = AvailableLanguagesClient.init(apiKey, config, transport);
24+
transportSpy = jest.fn(
25+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
26+
async (..._args: never): Promise<{ status: number; body: never }> => ({
27+
status: 200,
28+
body: {} as never,
29+
})
30+
);
31+
client = AvailableLanguagesClient.init(apiKey, config, transportSpy);
3432
});
3533

3634
it('should return instantiate an Available Languages Client instance', () => {
@@ -84,6 +82,6 @@ describe('Available Languages Client', () => {
8482
body: null,
8583
};
8684
await client.run();
87-
expect(transportSpy.calledOnceWith(transportArguments)).toEqual(true);
85+
expect(transportSpy).toHaveBeenNthCalledWith(1, transportArguments);
8886
});
8987
});

test/client/convert-to-3wa.spec.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { spy, SinonSpy } from 'sinon';
21
import { Chance } from 'chance';
32
import {
43
ApiClientConfiguration,
54
ApiVersion,
65
ConvertTo3waClient,
76
HEADERS,
8-
Transport,
97
} from '../../src';
108
import { generateCoordinate } from '../fixtures';
119

@@ -16,21 +14,22 @@ describe('Convert to 3wa Client', () => {
1614
let apiVersion: ApiVersion;
1715
let host: string;
1816
let config: ApiClientConfiguration;
19-
let transportSpy: SinonSpy;
20-
let transport: Transport;
17+
let transportSpy: jest.Mock<Promise<{ status: number; body: never }>, never>;
2118
let client: ConvertTo3waClient;
2219

2320
beforeEach(() => {
2421
apiKey = CHANCE.string({ length: 8 });
2522
apiVersion = ApiVersion.Version1;
2623
host = CHANCE.url({ path: '' });
2724
config = { host, apiVersion };
28-
transportSpy = spy();
29-
transport = async (...args) => {
30-
transportSpy(...args);
31-
return { status: 200, body: {} as never };
32-
};
33-
client = ConvertTo3waClient.init(apiKey, config, transport);
25+
transportSpy = jest.fn(
26+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
27+
async (..._args: never): Promise<{ status: number; body: never }> => ({
28+
status: 200,
29+
body: {} as never,
30+
})
31+
);
32+
client = ConvertTo3waClient.init(apiKey, config, transportSpy);
3433
});
3534

3635
it('should return instantiate an Convert to 3wa Client instance', () => {
@@ -94,9 +93,8 @@ describe('Convert to 3wa Client', () => {
9493
body: null,
9594
};
9695
await client.run({ coordinates, language, format });
97-
const actual = transportSpy.calledOnceWith(transportArguments);
9896

99-
expect(actual).toEqual(true);
97+
expect(transportSpy).toHaveBeenNthCalledWith(1, transportArguments);
10098
});
10199
it('should call /convert-to-3wa when run is called (no format/language)', async () => {
102100
const coordinates = generateCoordinate();
@@ -114,17 +112,16 @@ describe('Convert to 3wa Client', () => {
114112
body: null,
115113
};
116114
await client.run({ coordinates });
117-
const actual = transportSpy.calledOnceWith(transportArguments);
118115

119-
expect(actual).toEqual(true);
116+
expect(transportSpy).toHaveBeenNthCalledWith(1, transportArguments);
120117
});
121118
it('should throw error when no coordinates are provided', async () => {
122119
try {
123120
await client.run(undefined as never);
124121
} catch (err) {
125122
expect(err.message).toEqual('No coordinates provided');
126123
} finally {
127-
expect(transportSpy.notCalled).toEqual(true);
124+
expect(transportSpy).not.toHaveBeenCalled();
128125
}
129126
});
130127
});

0 commit comments

Comments
 (0)