Test results not showing when testing Node with Mocha

Tony Staunton

I am following the book Jump Start Node.js and am starting to write tests with mocha. My test output should show something similar to:

3 of 3 tests failed:
1) exchange buy should add a BUY nockmarket order:
ReferenceError: exhange is not defined

But instead what I am seeing is:

npm install make test
npm http GET https://registry.npmjs.org/make
npm http GET https://registry.npmjs.org/test
npm http 200 https://registry.npmjs.org/make
npm http 200 https://registry.npmjs.org/test
npm http GET https://registry.npmjs.org/ansi-font/0.0.2
npm http 200 https://registry.npmjs.org/ansi-font/0.0.2
npm http GET https://registry.npmjs.org/ansi-font/-/ansi-font-0.0.2.tgz
npm http 200 https://registry.npmjs.org/ansi-font/-/ansi-font-0.0.2.tgz
[email protected] node_modules/make

[email protected] node_modules/test
└── [email protected]

Am I missing something very simple? My test suite is as follows:

exchange.test.js

'use strict';

var assert = require('assert')
  , should = require('should');

var exchangeData = {};

suite('exchange', function() {
    test('buy should add a BUY nockmarket order', function(done) {
    exhangeData = exchange.buy(40, 100, exchangeData);
    exchangeData.buys.volumes[40].should.eql(100);
    done();
});

test('sell should add a SELL nockmarket order', function(done) {
    exchangeData = exchange.sell(41, 200, exchangeData);
    exchangeData.sells.volumes['41'].should.eql(200);
    done();
});

test('sell should produce trades', function(done) {
    exchangeData = exchange.sell(40, 75, exchangeData);
    exchangeData.trades[0].price.should.eql(40);
    exchangeData.trades[0].volume.should.eql(75);
    exchangeData.buys.volumes[40].should.eql(25);
    exchangeData.sells.volumes[41].should.eql(200);
    done();
});
});

package.json

{
      "name": "nockmarket"
    , "version": "0.0.1"
    , "private": true
    , "dependencies": {
          "jquery" : "1.7.3"
        , "mocha": "1.3.0"
        , "should": "1.0.0"

    }
}

Makefile

test:
    @./node_modules/.bin/mocha -u tdd
.PHONY: test

According to the books instructions I have Node installed correctly and I can run simple examples with no issues.

Any ideas would be very helpful.

Thanks, T.

Rodrigo Medeiros

NPM is the node package manager. If you're running

npm install

you're just installing the modules make and test, which is not what you want. If you want to run your tests, what you need to do is to run you make file

make -f your_make_file

, which is configured to run your mocha tests.

If your make file has a standard name (like makefile or Makefile, for example), you don't even need to specify it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Mocha for node js app in Visual Studio 2019 is not showing Tests in Test Explorer when reference or require another file

Error when import firebase-functions-test when testing with mocha

Testing node callbacks with mocha

How to get a Mocha test results report of a node applicaton in HTML

Mocha throwing errors when testing node.crypto functions

Testing angularjs modules with mocha in node

Node.js/Javascript: Failing mocha test with timeout on testing parsing XML to JSON

When testing async functions with Mocha/Chai, a failure to match an expectation always results in a timeout

JMeter is not showing any results when running a test plan

Node-Redis Asynchrounous testing using mocha

Testing with node, mocha and chai (should/bdd syntax)

Testing Error on node.js function with Mocha

Node mocha API testing with SocketIO and Express

Unusual behavior in testing: node.js/ Mocha

Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai

Error: cannot find module when testing with mocha

Handle WebPack CSS imports when testing with Mocha

node-mssql "connection is closed" when running Mocha test, but runs fine in app

PyTest test-suite passing when asserts should fail when testing another thread's results in Python?

Snowflake Node Query not showing Results

Mocha Testing Getting "getting 500 Unexpected JSON o in JSON at position 1" when I try to pass json object for test

using assert with ts-node in mocha test

How to test promise rejection with Mocha and Chai in Node?

Node mocha/chai test to see if a folder exists

node.js mocha test clearTimeout

How to visualize endpoint test results individually when load testing with k6, influxDB, and Grafana?

Testing Meteor application with Chimp/Mocha - automatic login to test authenticated routes

Testing express with Mocha: a promise-based test will not run by itself?

Stop webdriver when the mocha test times out