1
1
import { jest , expect } from '@jest/globals' ;
2
- import { alertForMiscreant } from './index' ;
2
+ import { alertForMiscreant , findMiscreant } from './index' ;
3
3
4
4
describe ( 'alertForMiscreant' , ( ) => {
5
5
const spy = jest . spyOn ( console , 'log' ) ;
@@ -24,3 +24,27 @@ describe('alertForMiscreant', () => {
24
24
expect ( spy ) . not . toHaveBeenCalled ( ) ;
25
25
} ) ;
26
26
} ) ;
27
+
28
+ describe ( 'findMiscreant' , ( ) => {
29
+ const spy = jest . spyOn ( console , 'log' ) ;
30
+
31
+ beforeEach ( ( ) => spy . mockClear ( ) ) ;
32
+
33
+ it ( 'should set off alarms for Don' , ( ) => {
34
+ const result = findMiscreant ( [ 'Don' ] ) ;
35
+ expect ( result ) . toBe ( 'Don' ) ;
36
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
37
+ } ) ;
38
+
39
+ it ( 'should set off alarms for John' , ( ) => {
40
+ const reuslt = findMiscreant ( [ 'John' ] ) ;
41
+ expect ( reuslt ) . toBe ( 'John' ) ;
42
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
43
+ } ) ;
44
+
45
+ it ( 'should not set off alarms for other people' , ( ) => {
46
+ const result = findMiscreant ( [ 'Alice' ] ) ;
47
+ expect ( result ) . toBe ( '' ) ;
48
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
49
+ } ) ;
50
+ } ) ;
0 commit comments