Tag: mocha

Mocha's glob behaviour

This question already has an answer here: Mocha only running one test file 1 answer

How to await and return the result of a http.request(), so that multiple requests run serially?

Assume there is a function doRequest(options), which is supposed to perform an HTTP request and uses http.request() for that. If doRequest() is called in a loop, I want that the next request is made after the previous finished (serial execution, one after another). In order to not mess with callbacks and Promises, I want to […]

How do I get mocha to run “exports”-style tests on Windows?

I have NodeJS and Mocha installed and working on Windows 7 x64 – so far, so good – but I can’t get Mocha to recognise any tests defined using the exports interface (as described at http://visionmedia.github.com/mocha/) If I create test/bdd.js containing the following code: var should = require(‘should’); describe(‘TestDemo – BDD interface’, function(){ describe(‘#foo’, function(){ […]

resetting Mongoose model cache

I’m trying to get mocha‘s –watch option to work. It works fine, until I have to do anything with a mongoose model. Apparently Mongoose keeps some sort of cache, from my understanding, and the error I get has been tracked and closed. The problem is, I’m a bit new to this whole thing and need […]

why mocha assertion fails on mongoose.Schema.objectId?

I am asserting somewhere in mocha as : assert.equal(model.organizationId,objId); But i am getting the failed mocha result as : Uncaught AssertionError: “5225777180a843d901000012” == “5225777180a843d901000012” why it happens, when the id’s are same. And how to overcome it?

How to Completely End a Test in Node Mocha Without Continuing

How do I force a Mochajs test to end completely without continuing on to the next tests. A scenario could be prevent any further tests if the environment was accidentally set to production and I need to prevent the tests from continuing. I’ve tried throwing Errors but those don’t stop the entire test because it’s […]

How to make mocha watch, compile and test coffeescript with dependencies on save

I’m working on a project that uses coffeescript for development and testing. I run the tests in node with mocha‘s –watch flag on so I can have the tests run automatically when I make changes. While this works to some extent, only the ./test/test.*.coffee files are recompiled when something is saved. This is my directory […]

Can zombie test that an element does not exist?

I’m trying to use zombie.js (with mocha) on an express app to make sure some elements don’t show on a page. Here’s how I try to do this: var app = require(‘../app).app, // this is express but you don’t care chai = require(‘chai’), should = chai.should(), Browser = require(‘zombie’), browser = new Browser(); describe(“page”, function() […]

Testing Errors passed back with Callbacks with mocha and should

UPDATE 2-July-2013 Using the last approach with the wrapped anonymous function can introduce some strange testing behavior. If you expect a thrown error, but there is an error in the actual execution the test will pass, but will pass on any error and probably not the one you were expecting. I do two things, if […]

Unittesting and mocking nodeJS net/Socket events

I’m TDD’ing a script that connects to a Socket from the net module. For testing I use mocha and for mocking sinonjs Now I’m really having problem mocking/faking the data-emitting of the Socket. e.g.: I want to test this code: socket.on(‘data’, function (data) { console.log(data); } How can I fake an emit of ‘data’?

Node.js is the Best Javascript runtime in the world.