File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 1
1
const test = require ( 'node:test' ) ;
2
+ const sinon = require ( 'sinon' ) ;
2
3
const assert = require ( 'assert' ) ;
3
4
const { Application, MailSystem } = require ( './main' ) ;
4
5
5
6
test ( 'Application selects and notifies a person' , ( ) => {
6
7
// Create a stub for MailSystem class
7
8
const mailSystemStub = {
8
- write : ( ) => 'Mocked context' ,
9
- send : ( ) => true ,
9
+ write : sinon . stub ( ) . returns ( 'Mocked context' ) ,
10
+ send : sinon . stub ( ) . returns ( true ) ,
10
11
} ;
11
12
12
13
const app = new Application ( ) ;
13
14
app . mailSystem = mailSystemStub ;
14
15
15
16
const selectedPerson = app . selectNextPerson ( ) ;
16
- assert . strictEqual ( selectedPerson !== null , true ) ; // Assuming a person is selected
17
+ assert ( selectedPerson !== null ) ; // Assuming a person is selected
17
18
18
19
app . notifySelected ( ) ;
19
20
20
- assert . strictEqual ( mailSystemStub . writeCalled , true ) ;
21
- assert . strictEqual ( mailSystemStub . sendCalled , true ) ;
21
+ // Assert that write and send methods of mailSystemStub were called
22
+ assert ( mailSystemStub . write . calledOnceWith ( selectedPerson ) ) ; // Check if write method was called with selected person
23
+ assert ( mailSystemStub . send . calledOnceWith ( selectedPerson , 'Mocked context' ) ) ; // Check if send method was called with correct arguments
22
24
} ) ;
You can’t perform that action at this time.
0 commit comments