Skip to content

Commit eb795b2

Browse files
committed
fix browser issues
1 parent 3754b50 commit eb795b2

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

__mocks__/@azure/msal-browser

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export class PublicClientApplication {
2+
constructor(configuration: any) {
3+
// Mock constructor
4+
}
5+
6+
initialize() {
7+
// Mock initialize method
8+
}
9+
10+
acquireTokenSilent() {
11+
// Mock acquireTokenSilent method
12+
return Promise.resolve({ accessToken: 'mock-access-token' });
13+
}
14+
15+
acquireTokenPopup() {
16+
// Mock acquireTokenPopup method
17+
return Promise.resolve({ accessToken: 'mock-access-token' });
18+
}
19+
20+
loginPopup() {
21+
// Mock loginPopup method
22+
return Promise.resolve({ account: { username: 'mock-user' } });
23+
}
24+
25+
logout() {
26+
// Mock logout method
27+
return Promise.resolve();
28+
}
29+
}

src/modules/authentication/msal-app.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ export const configuration: Configuration = {
2727
if (containsPii) {
2828
return;
2929
}
30+
switch (level) {
31+
case LogLevel.Error:
32+
console.error(message);
33+
return;
34+
case LogLevel.Info:
35+
console.info(message);
36+
return;
37+
case LogLevel.Verbose:
38+
console.debug(message);
39+
return;
40+
case LogLevel.Warning:
41+
console.warn(message);
42+
return;
43+
}
3044
},
3145
piiLoggingEnabled: false
3246
}

src/setupTests.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import { GlobalWithFetchMock } from 'jest-fetch-mock';
22
import 'jest-canvas-mock';
3+
import crypto from 'crypto';
34

45
const customGlobal: GlobalWithFetchMock = global as unknown as GlobalWithFetchMock;
56
customGlobal.fetch = require('jest-fetch-mock'); // tslint:disable-line
6-
customGlobal.fetchMock = customGlobal.fetch;
7+
customGlobal.fetchMock = customGlobal.fetch;
8+
9+
Object.defineProperty(global, 'crypto', {
10+
writable: true,
11+
value: {
12+
getRandomValues: (arr: Uint8Array) => crypto.getRandomValues(arr),
13+
subtle: {}
14+
}
15+
});
16+
17+
// Mock MSAL
18+
jest.mock('@azure/msal-browser');

0 commit comments

Comments
 (0)