Skip to content

Commit 4c36ae5

Browse files
fix jest?
1 parent bf94883 commit 4c36ae5

4 files changed

Lines changed: 42 additions & 14 deletions

File tree

src/v3/jest.setup.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ jest.mock('@okta/odyssey-react-mui', () => {
4848
odysseyTranslate: jest.fn().mockImplementation(
4949
// eslint-disable-next-line no-unused-vars
5050
(origKey, params) => {
51-
const keyAndBundle = origKey.split(':');
51+
const bundleAndKey = origKey.split(':');
5252
let bundle, key = origKey;
53-
if (keyAndBundle.length === 2) {
54-
([bundle, key] = keyAndBundle);
53+
if (bundleAndKey.length === 2) {
54+
([bundle, key] = bundleAndKey);
5555
return mockBundles[bundle][key] ? key : new Error(`Invalid i18n key: ${key}`);
5656
} else {
5757
return originalModule.odysseyTranslate(origKey, params);

src/v3/src/transformer/password/passwordSettingsUtils.test.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,24 @@ import { PASSWORD_REQUIREMENTS_KEYS } from '../../constants';
1414
import { ComplexityRequirements } from '../../types';
1515
import { getComplexityItems } from './passwordSettingsUtils';
1616

17-
jest.mock('util/loc', () => ({
18-
loc: jest.fn().mockImplementation(
19-
(key) => key,
20-
),
21-
}));
17+
jest.mock('@okta/odyssey-react-mui', () => {
18+
const originalModule = jest.requireActual('@okta/odyssey-react-mui');
19+
return {
20+
__esModule: true,
21+
...originalModule,
22+
odysseyTranslate: jest.fn().mockImplementation(
23+
// eslint-disable-next-line no-unused-vars
24+
(origKey, params) => {
25+
const bundleAndKey = origKey.split(':');
26+
let bundle, key = origKey;
27+
if (bundleAndKey.length === 2) {
28+
([bundle, key] = bundleAndKey);
29+
}
30+
return key;
31+
}
32+
),
33+
};
34+
});
2235

2336
describe('getComplexityItems', () => {
2437
it('should return excludeFirstName item', () => {

src/v3/src/util/locUtil.test.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,27 @@ describe('locUtil Tests', () => {
2121
};
2222

2323
beforeEach(() => {
24+
jest.unmock('@okta/odyssey-react-mui');
2425
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
25-
const mockedLoc = require('util/loc');
26-
mockedLoc.loc = jest.fn().mockImplementation(
27-
// eslint-disable-next-line no-unused-vars
28-
(key, _, params) => MockedBundle[key].replace('{0}', params?.[0]),
29-
);
26+
jest.mock('@okta/odyssey-react-mui', () => {
27+
const originalModule = jest.requireActual('@okta/odyssey-react-mui');
28+
return {
29+
__esModule: true,
30+
...originalModule,
31+
odysseyTranslate: jest.fn().mockImplementation(
32+
(origKey, params) => {
33+
const bundleAndKey = origKey.split(':');
34+
let bundle, key = origKey;
35+
if (bundleAndKey.length === 2) {
36+
([bundle, key] = bundleAndKey);
37+
return MockedBundle[key].replace('{0}', params?.[0]);
38+
} else {
39+
return originalModule.odysseyTranslate(origKey, params);
40+
}
41+
}
42+
),
43+
};
44+
});
3045
});
3146

3247
it('should return simple translated string', () => {

src/v3/test/integration/util/setup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type Options = CreateAuthClientOptions & {
3333
* According to jest documentation, must use the unmock function below
3434
* https://jestjs.io/docs/manual-mocks#examples
3535
*/
36-
jest.unmock('util/loc');
36+
jest.unmock('@okta/odyssey-react-mui');
3737

3838
export async function setup(options: Options): Promise<RenderResult & {
3939
authClient: OktaAuth;

0 commit comments

Comments
 (0)