Skip to content

Commit 8aff5cd

Browse files
authored
Update main_test.js
1 parent 33fde4f commit 8aff5cd

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lab2/main_test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
const test = require('node:test');
2+
const sinon = require('sinon');
23
const assert = require('assert');
34
const { Application, MailSystem } = require('./main');
45

56
test('Application selects and notifies a person', () => {
67
// Create a stub for MailSystem class
78
const mailSystemStub = {
8-
write: () => 'Mocked context',
9-
send: () => true,
9+
write: sinon.stub().returns('Mocked context'),
10+
send: sinon.stub().returns(true),
1011
};
1112

1213
const app = new Application();
1314
app.mailSystem = mailSystemStub;
1415

1516
const selectedPerson = app.selectNextPerson();
16-
assert.strictEqual(selectedPerson !== null, true); // Assuming a person is selected
17+
assert(selectedPerson !== null); // Assuming a person is selected
1718

1819
app.notifySelected();
1920

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
2224
});

0 commit comments

Comments
 (0)