File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
chapter_02-a-first-unit-test/MemCalculator Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,11 @@ function memCalculator() {
2323
2424 return temp ;
2525 }
26+
27+ return {
28+ add,
29+ result,
30+ } ;
2631}
2732
2833module . exports = memCalculator ;
Original file line number Diff line number Diff line change 1+ const memCalculator = require ( './memCalculator' ) ;
2+
3+ let memCalculatorInstance ;
4+ beforeEach ( ( ) => {
5+ memCalculatorInstance = memCalculator ( ) ;
6+ } ) ;
7+
8+ describe ( 'result' , ( ) => {
9+ it ( 'by default returns zero' , ( ) => {
10+ const lastResult = memCalculatorInstance . result ( ) ;
11+ expect ( lastResult ) . toBe ( 0 ) ;
12+ } ) ;
13+
14+ it ( 'changes when call add' , ( ) => {
15+ const expectedResult = 12 ;
16+
17+ memCalculatorInstance . add ( 5 ) ;
18+ memCalculatorInstance . add ( 7 ) ;
19+
20+ const lastResult = memCalculatorInstance . result ( ) ;
21+
22+ expect ( lastResult ) . toBe ( expectedResult ) ;
23+ } ) ;
24+ } ) ;
You can’t perform that action at this time.
0 commit comments