Skip to content

Commit

Permalink
add mock for reache.cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jthrilly committed Jul 29, 2024
1 parent 2f2e9cc commit 60dda9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions actions/interviews.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ vi.mock('~/lib/analytics', () => ({
trackEvent: vi.fn(),
}));

vi.mock('react', async (importOriginal) => {
const testCache = <T extends (...args: Array<unknown>) => unknown>(func: T) =>
func;
const originalModule = await importOriginal<typeof import('react')>();
return {
...originalModule,
cache: testCache,
};
});

describe('createInterview', () => {
it('should return an error if anonymous recruitment is not enabled and participantIdentifier is not provided ', async () => {
(prisma.appSettings.findFirst as Mock).mockResolvedValue({
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { defineConfig } from 'vitest/config';
export default defineConfig({
plugins: [tsconfigPaths(), react()],
test: {
environment: 'jsdom', // Defauult, but see below.
environment: 'jsdom', // Default, but see below.
// Tests for actions/queries shouldn't use the browser environment, because
// they can potentially import RSC modules (such as 'server-only') which
// don't export browser versions (meaning you can't mock them).
Expand Down

0 comments on commit 60dda9f

Please sign in to comment.