@@ -53,7 +53,7 @@ exports.CalculatorTest =
53
53
54
54
Before you can run your tests, you must install Nodeunit:
55
55
56
- First of allcreate a package.json file
56
+ First of all create a ` package.json ` file
57
57
58
58
{% highlight javascript %}
59
59
{
@@ -85,10 +85,21 @@ $ npm test
85
85
86
86
The test runner should fail, because we have no calculator.coffee
87
87
88
- <img src =" images/nodeunit_failing_all.png " alt =" All failing tests " />
88
+ suki@Yuzuki:nodeunit_testing (master)$ npm test
89
+ npm WARN package.json [email protected] No README.md file found!
89
90
90
- Let's create a simple file
91
+ > [email protected] test /Users/suki/tmp/nodeunit_testing
92
+ > ./node_modules/.bin/nodeunit test
93
+
94
+
95
+ /Users/suki/tmp/nodeunit_testing/node_modules/nodeunit/lib/nodeunit.js:72
96
+ if (err) throw err;
97
+ ^
98
+ Error: ENOENT, stat '/Users/suki/tmp/nodeunit_testing/test'
99
+ npm ERR! Test failed. See above for more details.
100
+ npm ERR! not ok code 0
91
101
102
+ Let's create a simple file
92
103
93
104
{% highlight coffeescript %}
94
105
@@ -101,7 +112,39 @@ module.exports = Calculator
101
112
102
113
And re-run the test suite.
103
114
104
- <img src =" images/nodeunit_failing_better.png " alt =" Still failing, but better " />
115
+ suki@Yuzuki:nodeunit_testing (master)$ npm test
116
+ npm WARN package.json [email protected] No README.md file found!
117
+
118
+ > [email protected] test /Users/suki/tmp/nodeunit_testing
119
+ > ./node_modules/.bin/nodeunit test
120
+
121
+
122
+ calculator.test
123
+ ✖ CalculatorTest - test can add two positive numbers
124
+
125
+ TypeError: Object #<Calculator> has no method 'add'
126
+ ...
127
+
128
+ ✖ CalculatorTest - test can handle negative number addition
129
+
130
+ TypeError: Object #<Calculator> has no method 'add'
131
+ ...
132
+
133
+ ✖ CalculatorTest - test can subtract two positive numbers
134
+
135
+ TypeError: Object #<Calculator> has no method 'subtract'
136
+ ...
137
+
138
+ ✖ CalculatorTest - test can handle negative number subtraction
139
+
140
+ TypeError: Object #<Calculator> has no method 'subtract'
141
+ ...
142
+
143
+
144
+ FAILURES: 4/4 assertions failed (31ms)
145
+ npm ERR! Test failed. See above for more details.
146
+ npm ERR! not ok code 0
147
+
105
148
106
149
## <span style =" color : green ;" >Getting the Tests to Pass</span >
107
150
@@ -124,7 +167,20 @@ module.exports = Calculator
124
167
125
168
When we rerun the tests we see they're all passing:
126
169
127
- <img src =" images/nodeunit_passing.png " alt =" All passing " />
170
+ suki@Yuzuki:nodeunit_testing (master)$ npm test
171
+ npm WARN package.json [email protected] No README.md file found!
172
+
173
+ > [email protected] test /Users/suki/tmp/nodeunit_testing
174
+ > ./node_modules/.bin/nodeunit test
175
+
176
+
177
+ calculator.test
178
+ ✔ CalculatorTest - test can add two positive numbers
179
+ ✔ CalculatorTest - test can handle negative number addition
180
+ ✔ CalculatorTest - test can subtract two positive numbers
181
+ ✔ CalculatorTest - test can handle negative number subtraction
182
+
183
+ OK: 4 assertions (27ms)
128
184
129
185
130
186
## <span style =" color : green ;" >Refactoring the Tests</span >
@@ -168,5 +224,3 @@ exports.CalculatorTest =
168
224
{% endhighlight %}
169
225
170
226
We can rerun the tests and everything should continue to pass.
171
-
172
- <img src =" images/nodeunit_passing.png " alt =" All passing " />
0 commit comments