Skip to content

Commit

Permalink
VADC-1644: add test support for RTKQuery (#8)
Browse files Browse the repository at this point in the history
* add cohortAp and hooks

* add teamProjectHooks.ts

* setup jest
test storybook with rtkQuery hooks

* add test support for RTKQ
add teamProjectHooks.test

* clean up test

* clean up test

* add sharp

* add sharp

* update to 0.10.79

* revert CohortDefinitions
refactor test-utils

* add error to useProjectHooks

* remove hook story

* remove cohortApi to keep PR smaller
  • Loading branch information
craigrbarnes authored Feb 3, 2025
1 parent ca96c53 commit 4d23c88
Show file tree
Hide file tree
Showing 10 changed files with 762 additions and 62 deletions.
2 changes: 2 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GEN3_COMMONS_NAME=gen3
NEXT_PUBLIC_GEN3_API=https://localhost
10 changes: 10 additions & 0 deletions __mocks__/createWebStorageMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* global jest */

const mockStorage = {
getItem: jest.fn((_key) => Promise.resolve(null)),
setItem: jest.fn((_key, item) => Promise.resolve(item)),
removeItem: jest.fn((_key) => Promise.resolve()),
};

const createWebStorage = (_arg) => mockStorage;
module.exports = createWebStorage;
32 changes: 32 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { JestConfigWithTsJest } from 'ts-jest';

const jestConfig: JestConfigWithTsJest = {
preset: 'ts-jest',
rootDir: __dirname,
roots: ['<rootDir>/src'],
moduleNameMapper: {
'^@/components(.*)$': '<rootDir>/src/components/$1',
'^@/lib/(.*)$': '<rootDir>/src/lib/$1',
'^redux-persist/lib/storage/createWebStorage$':
'<rootDir>/__mocks__/createWebStorageMock.js',
},
testEnvironment: 'jest-fixed-jsdom',
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
transform: {
'^.+\\.(ts|tsx)?$': [
'ts-jest',
{
isolatedModules: true,
tsconfig: 'tsconfig.test.json',
},
],
'node_modules/(flat|jsonpath-plus|uuid)/.+\\.(j|t)sx?$': ['ts-jest', {}],
},
transformIgnorePatterns: ['/node_modules/(?!(flat|jsonpath-plus|uuid))'],
modulePaths: ['<rootDir>'],
globals: {
fetch: global.fetch,
},
};

export default jestConfig;
4 changes: 4 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import '@testing-library/jest-dom';
import { loadEnvConfig } from '@next/env';

loadEnvConfig(__dirname, true, { info: () => null, error: console.error });
Loading

0 comments on commit 4d23c88

Please sign in to comment.