@@ -21,11 +21,15 @@ test('MailSystem should write mail correctly', (t) => {
21
21
// });
22
22
23
23
test ( 'MailSystem should send mail correctly' , ( t ) => {
24
- const sendMock = t . mock . fn ( MailSystem . prototype . send ) ;
25
- const success = sendMock ( 'Alice' , 'Congrats, Alice!' ) ;
26
- assert . strictEqual ( typeof success , 'boolean' ) ;
24
+ t . mock . method ( Math , 'random' ) . mock . mockImplementation ( ( ) => 0.6 ) ;
25
+ const success = MailSystem . prototype . send ( 'Alice' , 'Congrats, Alice!' ) ;
26
+ assert . strictEqual ( success , true ) ;
27
+ t . mock . method ( Math , 'random' ) . mock . mockImplementation ( ( ) => 0.4 ) ;
28
+ const failure = MailSystem . prototype . send ( 'Alice' , 'Congrats, Alice!' ) ;
29
+ assert . strictEqual ( failure , false ) ;
27
30
} ) ;
28
31
32
+
29
33
test ( 'Application should read file correctly' , async ( t ) => {
30
34
31
35
fs . writeFileSync ( TestData , 'Alice\nBob\nCharlie' , 'utf8' ) ;
@@ -71,21 +75,21 @@ test('Application should select next person', async (t) => {
71
75
} ) ;
72
76
73
77
test ( 'Application should notify person' , async ( t ) => {
78
+ const nameList = [ 'Alice' , 'Bob' , 'Charlie' ] ;
74
79
t . mock . method ( Application . prototype , 'getNames' , async ( ) => {
75
- return [ [ 'Alice' , 'Bob' , 'Charlie' ] , [ ] ] ;
80
+ return [ nameList , [ ] ] ;
76
81
} ) ;
77
82
const app = new Application ( ) ;
78
83
await app . getNames ( ) ;
79
84
80
- app . selectNextPerson ( ) ;
81
- console . log ( app . selected ) ;
85
+ app . selected = nameList ;
82
86
const writeMock = t . mock . method ( MailSystem . prototype , 'write' , ( ) => {
83
87
return true ;
84
88
} ) ;
85
89
const sendMock = t . mock . method ( MailSystem . prototype , 'send' , ( ) => {
86
90
return true ;
87
91
} ) ;
88
92
app . notifySelected ( ) ;
89
- assert . strictEqual ( writeMock . mock . callCount ( ) , 1 ) ;
90
- assert . strictEqual ( sendMock . mock . callCount ( ) , 1 ) ;
93
+ assert . strictEqual ( writeMock . mock . callCount ( ) , app . selected . length ) ;
94
+ assert . strictEqual ( sendMock . mock . callCount ( ) , app . selected . length ) ;
91
95
} ) ;
0 commit comments