Skip to content

Commit 775a3ab

Browse files
authored
Update main_test.js
1 parent e6b89b4 commit 775a3ab

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: lab2/main_test.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const test = require('node:test');
22
const assert = require('assert');
3+
const fs = require('fs');
34
const { Application, MailSystem } = require('./main');
45

5-
// TODO: write your tests here
6-
// Remember to use Stub, Mock, and Spy when necessary
6+
// Mock fs.readFile
77
test.mock.method(fs, 'readFile', (file, options, callback) => {
88
callback(null, 'Guan\nChen\nGala');
99
});
@@ -44,11 +44,13 @@ test("Application selectNextPerson", async () => {
4444
const application = new Application();
4545
await application.getNames();
4646
application.selected = ["Guan"];
47-
let count = 0;
47+
let count = 1;
4848
test.mock.method(application, 'getRandomPerson', () => {
4949
const name_list = application.people;
50-
if (count <= name_list.length) {
50+
if (count < name_list.length) {
5151
return name_list[count++];
52+
} else {
53+
return null;
5254
}
5355
});
5456
assert.strictEqual(application.selectNextPerson(), "Chen");

0 commit comments

Comments
 (0)