@@ -53,7 +53,7 @@ exports.CalculatorTest =
5353
5454Before you can run your tests, you must install Nodeunit:
5555
56- First of allcreate a package.json file
56+ First of all create a ` package.json ` file
5757
5858{% highlight javascript %}
5959{
@@ -85,10 +85,21 @@ $ npm test
8585
8686The test runner should fail, because we have no calculator.coffee
8787
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! 8990
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
91101
102+ Let's create a simple file
92103
93104{% highlight coffeescript %}
94105
@@ -101,7 +112,39 @@ module.exports = Calculator
101112
102113And re-run the test suite.
103114
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+
105148
106149## <span style =" color : green ;" >Getting the Tests to Pass</span >
107150
@@ -124,7 +167,20 @@ module.exports = Calculator
124167
125168When we rerun the tests we see they're all passing:
126169
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)
128184
129185
130186## <span style =" color : green ;" >Refactoring the Tests</span >
@@ -168,5 +224,3 @@ exports.CalculatorTest =
168224{% endhighlight %}
169225
170226We can rerun the tests and everything should continue to pass.
171-
172- <img src =" images/nodeunit_passing.png " alt =" All passing " />
0 commit comments