source: node_modules/@reduxjs/toolkit/src/entities/tests/utils.spec.ts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 2.1 KB
Line 
1import { noop } from '@internal/listenerMiddleware/utils'
2import { AClockworkOrange } from './fixtures/book'
3
4describe('Entity utils', () => {
5 describe(`selectIdValue()`, () => {
6 const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(noop)
7
8 beforeEach(() => {
9 vi.resetModules() // this is important - it clears the cache
10 vi.stubEnv('NODE_ENV', 'development')
11 })
12
13 afterEach(() => {
14 vi.unstubAllEnvs()
15 vi.clearAllMocks()
16 })
17
18 afterAll(() => {
19 vi.restoreAllMocks()
20 })
21
22 it('should not warn when key does exist', async () => {
23 const { selectIdValue } = await import('../utils')
24
25 selectIdValue(AClockworkOrange, (book: any) => book.id)
26 expect(consoleWarnSpy).not.toHaveBeenCalled()
27 })
28
29 it('should warn when key does not exist in dev mode', async () => {
30 const { selectIdValue } = await import('../utils')
31
32 expect(process.env.NODE_ENV).toBe('development')
33
34 selectIdValue(AClockworkOrange, (book: any) => book.foo)
35
36 expect(consoleWarnSpy).toHaveBeenCalledOnce()
37 })
38
39 it('should warn when key is undefined in dev mode', async () => {
40 const { selectIdValue } = await import('../utils')
41
42 expect(process.env.NODE_ENV).toBe('development')
43
44 const undefinedAClockworkOrange = { ...AClockworkOrange, id: undefined }
45 selectIdValue(undefinedAClockworkOrange, (book: any) => book.id)
46
47 expect(consoleWarnSpy).toHaveBeenCalledOnce()
48 })
49
50 it('should not warn when key does not exist in prod mode', async () => {
51 vi.stubEnv('NODE_ENV', 'production')
52
53 const { selectIdValue } = await import('../utils')
54
55 selectIdValue(AClockworkOrange, (book: any) => book.foo)
56
57 expect(consoleWarnSpy).not.toHaveBeenCalled()
58 })
59
60 it('should not warn when key is undefined in prod mode', async () => {
61 vi.stubEnv('NODE_ENV', 'production')
62
63 const { selectIdValue } = await import('../utils')
64
65 const undefinedAClockworkOrange = { ...AClockworkOrange, id: undefined }
66 selectIdValue(undefinedAClockworkOrange, (book: any) => book.id)
67
68 expect(consoleWarnSpy).not.toHaveBeenCalled()
69 })
70 })
71})
Note: See TracBrowser for help on using the repository browser.