File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 2020 },
2121 "devDependencies" : {
2222 "mocha" : " ^7.0.1" ,
23- "mocha-tap-reporter" : " ^0.1.3"
23+ "mocha-tap-reporter" : " ^0.1.3" ,
24+ "sinon" : " ^9.0.1"
2425 }
2526}
Original file line number Diff line number Diff line change 1+ const assert = require ( "assert" ) ;
2+ const sinon = require ( "sinon" ) ;
3+
4+ describe ( "server" , ( ) => {
5+ // 1.2
6+ it ( 'should log "Hello World"' , ( ) => {
7+ const spy = sinon . spy ( console , "log" ) ;
8+ // spy on the server
9+ const server = require ( "../src/server" ) ;
10+ const isCalled = spy . called
11+ const result = spy . calledWith ( "Hello World" ) ;
12+ // ensure connection is closed
13+ server . close ( ) ;
14+ assert . ok ( isCalled , 'console.log not called' )
15+ assert . ok ( result , '"Hello World was not logged' ) ;
16+ } ) . timeout ( 1000 )
17+ } ) ;
You can’t perform that action at this time.
0 commit comments