1
- import { selectIdValue } from '../utils'
2
1
import { AClockworkOrange } from './fixtures/book'
3
2
4
3
describe ( 'Entity utils' , ( ) => {
@@ -12,26 +11,29 @@ describe('Entity utils', () => {
12
11
13
12
afterEach ( ( ) => {
14
13
process . env = OLD_ENV
14
+ jest . resetAllMocks ( )
15
15
} )
16
16
17
17
it ( 'should not warn when key does exist' , ( ) => {
18
- const spy = spyOn ( console , 'warn' )
19
-
20
- selectIdValue ( AClockworkOrange , ( book ) => book . id )
18
+ const { selectIdValue } = require ( '../utils' )
19
+ const spy = jest . spyOn ( console , 'warn' )
21
20
21
+ selectIdValue ( AClockworkOrange , ( book : any ) => book . id )
22
22
expect ( spy ) . not . toHaveBeenCalled ( )
23
23
} )
24
24
25
25
it ( 'should warn when key does not exist in dev mode' , ( ) => {
26
- const spy = spyOn ( console , 'warn' )
26
+ const { selectIdValue } = require ( '../utils' )
27
+ const spy = jest . spyOn ( console , 'warn' )
27
28
28
29
selectIdValue ( AClockworkOrange , ( book : any ) => book . foo )
29
30
30
31
expect ( spy ) . toHaveBeenCalled ( )
31
32
} )
32
33
33
34
it ( 'should warn when key is undefined in dev mode' , ( ) => {
34
- const spy = spyOn ( console , 'warn' )
35
+ const { selectIdValue } = require ( '../utils' )
36
+ const spy = jest . spyOn ( console , 'warn' )
35
37
36
38
const undefinedAClockworkOrange = { ...AClockworkOrange , id : undefined }
37
39
selectIdValue ( undefinedAClockworkOrange , ( book : any ) => book . id )
@@ -41,7 +43,8 @@ describe('Entity utils', () => {
41
43
42
44
it ( 'should not warn when key does not exist in prod mode' , ( ) => {
43
45
process . env . NODE_ENV = 'production'
44
- const spy = spyOn ( console , 'warn' )
46
+ const { selectIdValue } = require ( '../utils' )
47
+ const spy = jest . spyOn ( console , 'warn' )
45
48
46
49
selectIdValue ( AClockworkOrange , ( book : any ) => book . foo )
47
50
@@ -50,7 +53,8 @@ describe('Entity utils', () => {
50
53
51
54
it ( 'should not warn when key is undefined in prod mode' , ( ) => {
52
55
process . env . NODE_ENV = 'production'
53
- const spy = spyOn ( console , 'warn' )
56
+ const { selectIdValue } = require ( '../utils' )
57
+ const spy = jest . spyOn ( console , 'warn' )
54
58
55
59
const undefinedAClockworkOrange = { ...AClockworkOrange , id : undefined }
56
60
selectIdValue ( undefinedAClockworkOrange , ( book : any ) => book . id )
0 commit comments