From 6ce679313f98dc678bb324881aaeb33e66469f7d Mon Sep 17 00:00:00 2001 From: abhip2565 Date: Tue, 24 Jun 2025 18:52:18 +0530 Subject: [PATCH] [INJIMOB-3303]: fix failing test (#1978) Signed-off-by: Abhishek Paul Co-authored-by: Alka Prasad --- __mocks__/text-encoder.js | 4 +++ components/ActivityLogEvent.test.ts | 44 +++++++++++++++++------------ jest.config.js | 11 ++++---- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 __mocks__/text-encoder.js diff --git a/__mocks__/text-encoder.js b/__mocks__/text-encoder.js new file mode 100644 index 00000000..2c713c33 --- /dev/null +++ b/__mocks__/text-encoder.js @@ -0,0 +1,4 @@ +import {TextDecoder, TextEncoder} from 'text-encoding'; + +global.TextDecoder = TextDecoder; +global.TextEncoder = TextEncoder; diff --git a/components/ActivityLogEvent.test.ts b/components/ActivityLogEvent.test.ts index fe96aea0..9fd2f71d 100644 --- a/components/ActivityLogEvent.test.ts +++ b/components/ActivityLogEvent.test.ts @@ -1,10 +1,14 @@ import {VCActivityLog} from './ActivityLogEvent'; describe('ActivityLog', () => { - let instance: { timestamp: any; }; + let instance: {timestamp: any}; beforeEach(() => { instance = new VCActivityLog(); + jest.mock('jsonld', () => ({ + compact: jest.fn(), + expand: jest.fn(), + })); }); it('Activity log instance should have a timestamp set', () => { @@ -16,28 +20,32 @@ describe('getActionText', () => { let activityLog; let mockIl18nfn; let wellknown = { - "credential_configurations_supported": { - "mockId": { - "display": [ + credential_configurations_supported: { + mockId: { + display: [ { - "name": "fake VC", - "locale": "en", - "logo": { - "url": "https://mosip.github.io/inji-config/logos/mosipid-logo.png", - "alt_text": "a square logo of a MOSIP" + name: 'fake VC', + locale: 'en', + logo: { + url: 'https://mosip.github.io/inji-config/logos/mosipid-logo.png', + alt_text: 'a square logo of a MOSIP', }, - "background_color": "#1A0983", - "background_image": { - "uri": "https://mosip.github.io/inji-config/logos/mosipid-logo.png" + background_color: '#1A0983', + background_image: { + uri: 'https://mosip.github.io/inji-config/logos/mosipid-logo.png', }, - "text_color": "#000000" - } + text_color: '#000000', + }, ], - } - } - } + }, + }, + }; beforeEach(() => { mockIl18nfn = jest.fn(); + jest.mock('jsonld', () => ({ + compact: jest.fn(), + expand: jest.fn(), + })); activityLog = new VCActivityLog({ id: 'mockId', credentialConfigurationId: 'mockId', @@ -58,7 +66,7 @@ describe('getActionText', () => { }); activityLog.getActionText(mockIl18nfn, wellknown); expect(mockIl18nfn).toHaveBeenCalledWith('mockType', { - idType: 'fake VC' + idType: 'fake VC', }); expect(mockIl18nfn).toHaveBeenCalledTimes(1); // TODO: assert the returned string diff --git a/jest.config.js b/jest.config.js index 40647b3c..7111b167 100644 --- a/jest.config.js +++ b/jest.config.js @@ -28,11 +28,11 @@ module.exports = { // Not quite sure about the reason. testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$', coveragePathIgnorePatterns: [ - "node_modules", - "test-config", - "interfaces", - "jestGlobalMocks.ts", - "__mocks__/*" + 'node_modules', + 'test-config', + 'interfaces', + 'jestGlobalMocks.ts', + '__mocks__/*', ], transformIgnorePatterns: [ 'node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)', @@ -53,6 +53,7 @@ module.exports = { '/__mocks__/@noble/mock-ed25519.js', '/__mocks__/react-native-base64.js', '__mocks__/mockCrytoUtil.js', + '__mocks__/text-encoder.js', // https://github.com/react-native-google-signin/google-signin?tab=readme-ov-file#jest-module-mock '/node_modules/@react-native-google-signin/google-signin/jest/build/setup.js', ], diff --git a/package-lock.json b/package-lock.json index 112d4464..4d02320e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -102,7 +102,6 @@ "short-unique-id": "^4.4.4", "simple-pem2jwk": "^0.2.4", "telemetry-sdk": "git://github.com/mosip/sunbird-telemetry-sdk.git#f762be5732ee552c0c70bdd540aa4e2701554c71", - "text-encoding": "^0.7.0", "uuid": "^11.0.3", "xstate": "^4.35.0" }, @@ -146,6 +145,7 @@ "react-native-share": "^10.2.1", "react-native-svg-transformer": "^1.1.0", "react-native-url-polyfill": "^2.0.0", + "text-encoding": "^0.7.0", "ts-jest": "^29.1.1", "typescript": "~5.3.3" }, diff --git a/package.json b/package.json index 56082c13..08da5e23 100644 --- a/package.json +++ b/package.json @@ -107,7 +107,6 @@ "short-unique-id": "^4.4.4", "simple-pem2jwk": "^0.2.4", "telemetry-sdk": "git://github.com/mosip/sunbird-telemetry-sdk.git#f762be5732ee552c0c70bdd540aa4e2701554c71", - "text-encoding": "^0.7.0", "uuid": "^11.0.3", "xstate": "^4.35.0" }, @@ -151,6 +150,7 @@ "react-native-share": "^10.2.1", "react-native-svg-transformer": "^1.1.0", "react-native-url-polyfill": "^2.0.0", + "text-encoding": "^0.7.0", "ts-jest": "^29.1.1", "typescript": "~5.3.3" },