Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions nexus/frontend/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Config } from 'jest';

const config: Config = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
transform: {
'^.+\\.tsx?$': ['ts-jest', {
tsconfig: 'tsconfig.json',
}],
},
};

export default config;
6 changes: 6 additions & 0 deletions nexus/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@
"zod": "^4.3.6"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
"@types/babel__traverse": "^7.28.0",
"@types/jest": "^30.0.0",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "16.1.6",
"jest": "^30.4.0",
"jest-environment-jsdom": "^30.4.0",
Comment thread
Adityavanjre marked this conversation as resolved.
"tailwindcss": "^3.4.1",
"ts-jest": "^29.4.9",
"typescript": "^5"
}
}
27 changes: 27 additions & 0 deletions nexus/frontend/src/lib/network-consent.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe('network-consent', () => {
let hasNetworkConsent: () => boolean;

beforeEach(async () => {
jest.resetModules();
const networkConsentModule = await import('./network-consent');
hasNetworkConsent = networkConsentModule.hasNetworkConsent;
});

afterEach(() => {
jest.restoreAllMocks();
});

describe('hasNetworkConsent', () => {
it('should return false if sessionStorage.getItem throws', () => {
// Mock getItem to throw
const getItemSpy = jest.spyOn(window.sessionStorage.__proto__, 'getItem').mockImplementation(() => {
throw new Error('Access denied');
});

const result = hasNetworkConsent();

expect(result).toBe(false);
expect(getItemSpy).toHaveBeenCalledWith('k_network_consent_granted');
});
});
});
Loading
Loading