File tree Expand file tree Collapse file tree 1 file changed +28
-8
lines changed Expand file tree Collapse file tree 1 file changed +28
-8
lines changed Original file line number Diff line number Diff line change 1
- import { myPackage } from '../src' ;
1
+ import { logger } from '../src/index ' ;
2
2
3
- describe ( 'index' , ( ) => {
4
- describe ( 'myPackage' , ( ) => {
5
- it ( 'should return a string containing the message' , ( ) => {
6
- const message = 'Hello' ;
3
+ describe ( 'Logger' , ( ) => {
4
+ let consoleLogSpy : jest . SpyInstance ;
7
5
8
- const result = myPackage ( message ) ;
6
+ beforeEach ( ( ) => {
7
+ consoleLogSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
8
+ } ) ;
9
+
10
+ afterEach ( ( ) => {
11
+ consoleLogSpy . mockRestore ( ) ;
12
+ } ) ;
13
+
14
+ it ( "should log a message when NODE_ENV is not 'production'" , ( ) => {
15
+ process . env . NODE_ENV = 'development' ;
16
+ const message = 'Test log message' ;
17
+
18
+ logger . log ( message ) ;
19
+
20
+ expect ( consoleLogSpy ) . toHaveBeenCalledWith (
21
+ expect . stringMatching ( / \[ L O G \] .* : T e s t l o g m e s s a g e / )
22
+ ) ;
23
+ } ) ;
24
+
25
+ it ( "should not log a message when NODE_ENV is 'production'" , ( ) => {
26
+ process . env . NODE_ENV = 'production' ;
27
+ const message = 'Test log message' ;
28
+
29
+ logger . log ( message ) ;
9
30
10
- expect ( result ) . toMatch ( message ) ;
11
- } ) ;
31
+ expect ( consoleLogSpy ) . not . toHaveBeenCalled ( ) ;
12
32
} ) ;
13
33
} ) ;
You can’t perform that action at this time.
0 commit comments