Skip to content

Commit

Permalink
fix jest?
Browse files Browse the repository at this point in the history
  • Loading branch information
denysoblohin-okta committed Aug 9, 2024
1 parent bf94883 commit 4c36ae5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/v3/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jest.mock('@okta/odyssey-react-mui', () => {
odysseyTranslate: jest.fn().mockImplementation(
// eslint-disable-next-line no-unused-vars
(origKey, params) => {
const keyAndBundle = origKey.split(':');
const bundleAndKey = origKey.split(':');
let bundle, key = origKey;
if (keyAndBundle.length === 2) {
([bundle, key] = keyAndBundle);
if (bundleAndKey.length === 2) {
([bundle, key] = bundleAndKey);
return mockBundles[bundle][key] ? key : new Error(`Invalid i18n key: ${key}`);
} else {
return originalModule.odysseyTranslate(origKey, params);
Expand Down
23 changes: 18 additions & 5 deletions src/v3/src/transformer/password/passwordSettingsUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,24 @@ import { PASSWORD_REQUIREMENTS_KEYS } from '../../constants';
import { ComplexityRequirements } from '../../types';
import { getComplexityItems } from './passwordSettingsUtils';

jest.mock('util/loc', () => ({
loc: jest.fn().mockImplementation(
(key) => key,
),
}));
jest.mock('@okta/odyssey-react-mui', () => {
const originalModule = jest.requireActual('@okta/odyssey-react-mui');
return {
__esModule: true,
...originalModule,
odysseyTranslate: jest.fn().mockImplementation(
// eslint-disable-next-line no-unused-vars
(origKey, params) => {
const bundleAndKey = origKey.split(':');
let bundle, key = origKey;
if (bundleAndKey.length === 2) {
([bundle, key] = bundleAndKey);
}
return key;
}
),
};
});

describe('getComplexityItems', () => {
it('should return excludeFirstName item', () => {
Expand Down
25 changes: 20 additions & 5 deletions src/v3/src/util/locUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,27 @@ describe('locUtil Tests', () => {
};

beforeEach(() => {
jest.unmock('@okta/odyssey-react-mui');
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
const mockedLoc = require('util/loc');
mockedLoc.loc = jest.fn().mockImplementation(
// eslint-disable-next-line no-unused-vars
(key, _, params) => MockedBundle[key].replace('{0}', params?.[0]),
);
jest.mock('@okta/odyssey-react-mui', () => {
const originalModule = jest.requireActual('@okta/odyssey-react-mui');
return {
__esModule: true,
...originalModule,
odysseyTranslate: jest.fn().mockImplementation(
(origKey, params) => {
const bundleAndKey = origKey.split(':');
let bundle, key = origKey;
if (bundleAndKey.length === 2) {
([bundle, key] = bundleAndKey);
return MockedBundle[key].replace('{0}', params?.[0]);
} else {
return originalModule.odysseyTranslate(origKey, params);
}
}
),
};
});
});

it('should return simple translated string', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/v3/test/integration/util/setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Options = CreateAuthClientOptions & {
* According to jest documentation, must use the unmock function below
* https://jestjs.io/docs/manual-mocks#examples
*/
jest.unmock('util/loc');
jest.unmock('@okta/odyssey-react-mui');

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

0 comments on commit 4c36ae5

Please sign in to comment.