Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions article1.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('CartSummary', function() {

The `describe` function is used to set up a group of tests with a name. I tend to put the module under test as the name, in this case `CartSummary`. A test is written using the `it` function. The `it` function is given a description as the first argument of what the module under test should do. The second argument of the `it` function is a function that will contain one or more assertions (also called expectations) using Chai in this example. Our first test simply verifies that the subtotal is 0 if the cart has no items.

To run this test, run `mocha tests --recursive --watch` from the root of the project. The recursive flag will find all files in subdirectories, and the watch flag will watch all your source and test files and rerun the tests when they change. You should see something like this:
To run this test, run `mocha tests --recursive --expose-internals` from the root of the project. The recursive flag will find all files in subdirectories, and the watch flag will watch all your source and test files and rerun the tests when they change. You should see something like this:

![failing-test-1.png](failing-test-1.png)

Expand Down Expand Up @@ -156,9 +156,10 @@ Now that `tax.calculate` has been created, we can stub it out with our pre-progr
var sinon = require('sinon');
var tax = require('./../../src/part1/tax');


describe('getTax()', function() {
beforeEach(function() {
sinon.stub(tax, 'calculate', function(subtotal, state, done) {
sinon.stub(tax, 'calculate').callsFake(function(subtotal, state, done) {
setTimeout(function() {
done({
amount: 30
Expand Down
2 changes: 1 addition & 1 deletion tests/part1/cart-summary-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var tax = require('./../../src/part1/tax');

describe('CartSummary', function() {
beforeEach(function() {
sinon.stub(tax, 'calculate', function(subtotal, state, done) {
sinon.stub(tax, 'calculate').callsFake(function(subtotal, state, done) {
setTimeout(function() {
done({
amount: 30
Expand Down