Skip to content

Commit 386cfeb

Browse files
committed
test: fixed broken mocking
1 parent fac79cb commit 386cfeb

File tree

7 files changed

+15
-46
lines changed

7 files changed

+15
-46
lines changed

tests/identities/allowDisallowPermissions.test.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ import { encodeProviderIdentityId } from '@matrixai/polykey/dist/identities/util
1818
import TestProvider from '../TestProvider';
1919
import * as testUtils from '../utils';
2020

21-
// Fixes problem with spyOn overriding imports directly
22-
const mocks = {
23-
browser: identitiesUtils.browser,
24-
};
21+
// @ts-ignore: stub out method
22+
identitiesUtils.browser = () => {};
2523

2624
describe('allow/disallow/permissions', () => {
2725
const logger = new Logger('allow/disallow/permissions test', LogLevel.WARN, [
@@ -241,10 +239,6 @@ describe('allow/disallow/permissions', () => {
241239
cwd: dataDir,
242240
},
243241
);
244-
// Authenticate our own identity in order to query the provider
245-
const mockedBrowser = jest
246-
.spyOn(mocks, 'browser')
247-
.mockImplementation(() => {});
248242
await testUtils.pkStdio(
249243
[
250244
'identities',
@@ -260,7 +254,6 @@ describe('allow/disallow/permissions', () => {
260254
cwd: dataDir,
261255
},
262256
);
263-
mockedBrowser.mockRestore();
264257
// Must first trust identity before we can set permissions
265258
// This is because trusting the identity sets it in our gestalt graph,
266259
// which we need in order to set permissions

tests/identities/authenticateAuthenticated.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import * as keysUtils from '@matrixai/polykey/dist/keys/utils/index';
1313
import TestProvider from '../TestProvider';
1414
import * as testUtils from '../utils';
1515

16-
// Fixes problem with spyOn overriding imports directly
17-
const mocks = {
18-
browser: identitiesUtils.browser,
19-
};
16+
// @ts-ignore: stub out method
17+
identitiesUtils.browser = () => {};
2018

2119
describe('authenticate/authenticated', () => {
2220
const logger = new Logger('authenticate/authenticated test', LogLevel.WARN, [
@@ -66,9 +64,6 @@ describe('authenticate/authenticated', () => {
6664
async () => {
6765
// Can't test with target command due to mocking
6866
let exitCode, stdout;
69-
const mockedBrowser = jest
70-
.spyOn(mocks, 'browser')
71-
.mockImplementation(() => {});
7267
// Authenticate an identity
7368
({ exitCode, stdout } = await testUtils.pkStdio(
7469
[
@@ -126,7 +121,6 @@ describe('authenticate/authenticated', () => {
126121
providerId: testToken.providerId,
127122
identityId: testToken.identityId,
128123
});
129-
mockedBrowser.mockRestore();
130124
},
131125
);
132126
testUtils.testIf(testUtils.isTestPlatformEmpty)(

tests/identities/claim.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ import * as keysUtils from '@matrixai/polykey/dist/keys/utils/index';
1414
import TestProvider from '../TestProvider';
1515
import * as testUtils from '../utils';
1616

17-
// Fixes problem with spyOn overriding imports directly
18-
const mocks = {
19-
browser: identitiesUtils.browser,
20-
};
17+
// @ts-ignore: stub out method
18+
identitiesUtils.browser = () => {};
2119

2220
describe('claim', () => {
2321
const logger = new Logger('claim test', LogLevel.WARN, [new StreamHandler()]);
@@ -64,9 +62,6 @@ describe('claim', () => {
6462
'claims an identity',
6563
async () => {
6664
// Need an authenticated identity
67-
const mockedBrowser = jest
68-
.spyOn(mocks, 'browser')
69-
.mockImplementation(() => {});
7065
await testUtils.pkStdio(
7166
[
7267
'identities',
@@ -110,7 +105,6 @@ describe('claim', () => {
110105
expect(claim).toBeDefined();
111106
expect(claim!.id).toBe('0');
112107
// Expect(claim!.payload.data.type).toBe('identity');
113-
mockedBrowser.mockRestore();
114108
},
115109
);
116110
testUtils.testIf(testUtils.isTestPlatformEmpty)(

tests/identities/discoverGet.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
1212
import PolykeyAgent from '@matrixai/polykey/dist/PolykeyAgent';
1313
import { sysexits } from '@matrixai/polykey/dist/utils';
1414
import * as nodesUtils from '@matrixai/polykey/dist/nodes/utils';
15+
import * as identitiesUtils from '@matrixai/polykey/dist/identities/utils';
1516
import * as keysUtils from '@matrixai/polykey/dist/keys/utils/index';
1617
import { encodeProviderIdentityId } from '@matrixai/polykey/dist/identities/utils';
1718
import TestProvider from '../TestProvider';
1819
import * as testUtils from '../utils';
1920

21+
// @ts-ignore: stub out method
22+
identitiesUtils.browser = () => {};
23+
2024
describe('discover/get', () => {
2125
const logger = new Logger('discover/get test', LogLevel.WARN, [
2226
new StreamHandler(),

tests/identities/search.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ import * as keysUtils from '@matrixai/polykey/dist/keys/utils/index';
1414
import TestProvider from '../TestProvider';
1515
import * as testUtils from '../utils';
1616

17-
// Fixes problem with spyOn overriding imports directly
18-
const mocks = {
19-
browser: identitiesUtils.browser,
20-
};
17+
// @ts-ignore: stub out method
18+
identitiesUtils.browser = () => {};
2119

2220
describe('search', () => {
2321
const logger = new Logger('search test', LogLevel.WARN, [
@@ -153,9 +151,6 @@ describe('search', () => {
153151
// Can't test with target executable due to mocking
154152
let exitCode, stdout;
155153
let searchResults: Array<IdentityData>;
156-
const mockedBrowser = jest
157-
.spyOn(mocks, 'browser')
158-
.mockImplementation(() => {});
159154
// Search with no authenticated identities
160155
// Should return nothing
161156
({ exitCode, stdout } = await testUtils.pkStdio(
@@ -344,7 +339,6 @@ describe('search', () => {
344339
expect(exitCode).toBe(0);
345340
searchResults = stdout.split('\n').slice(undefined, -1).map(JSON.parse);
346341
expect(searchResults).toHaveLength(2);
347-
mockedBrowser.mockRestore();
348342
},
349343
);
350344
testUtils.testIf(testUtils.isTestPlatformEmpty)(

tests/identities/trustUntrustList.test.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ import { encodeProviderIdentityId } from '@matrixai/polykey/dist/identities/util
1818
import TestProvider from '../TestProvider';
1919
import * as testUtils from '../utils';
2020

21-
// Fixes problem with spyOn overriding imports directly
22-
const mocks = {
23-
browser: identitiesUtils.browser,
24-
};
21+
// @ts-ignore: stub out method
22+
identitiesUtils.browser = () => {};
2523

2624
describe('trust/untrust/list', () => {
2725
const logger = new Logger('trust/untrust/list test', LogLevel.WARN, [
@@ -130,9 +128,6 @@ describe('trust/untrust/list', () => {
130128
cwd: dataDir,
131129
},
132130
);
133-
const mockedBrowser = jest
134-
.spyOn(mocks, 'browser')
135-
.mockImplementation(() => {});
136131
await testUtils.pkStdio(
137132
[
138133
'identities',
@@ -148,7 +143,6 @@ describe('trust/untrust/list', () => {
148143
cwd: dataDir,
149144
},
150145
);
151-
mockedBrowser.mockRestore();
152146
// Trust node - this should trigger discovery on the gestalt the node
153147
// belongs to and add it to our gestalt graph
154148
({ exitCode } = await testUtils.pkStdio(
@@ -264,9 +258,6 @@ describe('trust/untrust/list', () => {
264258
cwd: dataDir,
265259
},
266260
);
267-
const mockedBrowser = jest
268-
.spyOn(mocks, 'browser')
269-
.mockImplementation(() => {});
270261
await testUtils.pkStdio(
271262
[
272263
'identities',
@@ -282,7 +273,6 @@ describe('trust/untrust/list', () => {
282273
cwd: dataDir,
283274
},
284275
);
285-
mockedBrowser.mockRestore();
286276
// Trust identity - this should trigger discovery on the gestalt the node
287277
// belongs to and add it to our gestalt graph
288278
// This command should fail first time as we need to allow time for the

tests/sessions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import * as testUtils from './utils';
1616
jest.mock('prompts');
1717

1818
describe('sessions', () => {
19-
const logger = new Logger('sessions test', LogLevel.DEBUG, [
19+
const logger = new Logger('sessions test', LogLevel.WARN, [
2020
new StreamHandler(),
2121
]);
2222
let agentDir;

0 commit comments

Comments
 (0)