Skip to content

Commit 3b114a4

Browse files
committed
additional test improvements
1 parent 6a26eff commit 3b114a4

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/integrationTests/basic.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ testCookieAndLocalStorage(() => {
306306
expect(xhrMock.send).toHaveBeenCalledTimes(1);
307307
expect(xhrMock.open).toHaveBeenLastCalledWith('POST', uid2RefreshUrl, true);
308308
expect(xhrMock.send).toHaveBeenLastCalledWith(identity.refresh_token);
309-
xhrMock.onreadystatechange();
309+
xhrMock.onreadystatechange(new Event(''));
310310
expect(cryptoMock.subtle.importKey).toHaveBeenCalled();
311311
});
312312

@@ -334,7 +334,7 @@ testCookieAndLocalStorage(() => {
334334
expect(xhrMock.send).toHaveBeenCalledTimes(1);
335335
expect(xhrMock.open).toHaveBeenLastCalledWith('POST', uid2RefreshUrl, true);
336336
expect(xhrMock.send).toHaveBeenLastCalledWith(identity.refresh_token);
337-
xhrMock.onreadystatechange();
337+
xhrMock.onreadystatechange(new Event(''));
338338
expect(cryptoMock.subtle.importKey).toHaveBeenCalledTimes(0);
339339
mocks.resetCrypto(sdkWindow);
340340
});
@@ -479,7 +479,7 @@ testCookieAndLocalStorage(() => {
479479
identity: originalIdentity,
480480
useCookie: useCookie,
481481
});
482-
let cryptoMock = new mocks.CryptoMock(sdkWindow);
482+
new mocks.CryptoMock(sdkWindow);
483483
});
484484
afterEach(() => {
485485
mocks.resetCrypto(sdkWindow);
@@ -755,7 +755,7 @@ testCookieAndLocalStorage(() => {
755755
identity: originalIdentity,
756756
useCookie: useCookie,
757757
});
758-
let cryptoMock = new mocks.CryptoMock(sdkWindow);
758+
new mocks.CryptoMock(sdkWindow);
759759
});
760760
afterEach(() => {
761761
mocks.resetCrypto(sdkWindow);
@@ -1016,14 +1016,20 @@ describe('SDK bootstraps itself if init has already been completed', () => {
10161016
const phone = '+12345678901';
10171017
const phoneHash = 'EObwtHBUqDNZR33LNSMdtt5cafsYFuGmuY4ZLenlue4=';
10181018

1019+
let callCstgApiSpy: jest.SpiedFunction<ApiClient['callCstgApi']>;
1020+
10191021
beforeEach(() => {
10201022
sdkWindow.__uid2 = new UID2();
10211023
});
10221024

1025+
afterEach(() => {
1026+
callCstgApiSpy?.mockRestore();
1027+
});
1028+
10231029
test('should bootstrap therefore public functions should return the correct values without calling init again', async () => {
10241030
const identity = { ...makeIdentity(), refresh_from: Date.now() + 100 };
10251031

1026-
jest
1032+
callCstgApiSpy = jest
10271033
.spyOn(ApiClient.prototype, 'callCstgApi')
10281034
.mockResolvedValue({ status: 'success', identity });
10291035

0 commit comments

Comments
 (0)