Questions tagged [nodeunit]

A unit testing framework in node.js and the browser, based on the assert module.

Nodeunit provides easy unit testing in node.js and the browser, based on the assert module.

99 questions
19
votes
4 answers

When using Sinon, how to replace stub function in a stub instance?

If I have create a instance by var a = sinon.createStubInstance(MyContructor). How can I replace one of the stubbed function like var stub = sinon.stub(object, "method", func);. The main reason I am doing this is want to achieve multiple callback…
StevenR
  • 702
  • 1
  • 8
  • 17
11
votes
4 answers

Nodeunit command not found?

I'm running on Windows 7 and have node installed fine with cygwin. I am following along on the how to on mcmahon's website for nodeunit: http://caolanmcmahon.com/posts/unit_testing_in_node_js . I used npm to install nodeunit and it said it had…
WildaBeast
  • 438
  • 1
  • 5
  • 13
11
votes
2 answers

how to debug nodeunit using node-inspector

I can do: I can test node.js modules using nodeunit. I can debug my node.js express site using node inspector. But how to debug nodeunit test using node inspector? I tried, but not working: nodeunit --debug myNodeUnitModule_test.js It's not…
Maxim Yefremov
  • 13,671
  • 27
  • 117
  • 166
9
votes
1 answer

Nodeunit test.throws doesn't seem to catch the error

I am trying to create a test suite for a module that I am writing in Node.js using Nodeunit. The module is a basic music playlist that allows adding and removing tracks to the playlist. var playlist = function(){ this.__playlist = []; …
Dave Long
  • 9,569
  • 14
  • 59
  • 89
9
votes
1 answer

How to test a Grunt task? Understanding and best practices

I'm a bit stuck with understanding how to write complicated Gruntfile.js and use it with tests. Am I using Grunt in a right way? I would like to ask community for help and contribute in an other way. I'm writing a new task for Grunt and want to…
Dan
  • 55,715
  • 40
  • 116
  • 154
8
votes
1 answer

Nodeunit: Runtime/thrown errors in test function are _silent_

One of the points of using NodeUnit is to write new functions and test them often. Problem is, if one of the tested functions throws an error (including JS runtime errors), the error is not shown to the user. Here is the simplest possible test case:…
Merc
  • 16,277
  • 18
  • 79
  • 122
8
votes
1 answer

Structure for unit testing on node.js with mongoose

I've been developing with node.js for months but now I'm starting a new project and I'd like to know how to structure the app. My problem comes when talking about unit testing. I will use nodeunit to write unit tests. Also I'm using express to…
Javier Manzano
  • 4,761
  • 16
  • 56
  • 86
7
votes
2 answers

How to use the node.js module 'nodeunit' with coffeescript files

I'm trying to get the nodeunit module working within a coffeescript project but can't seem to get even a basic test to run. Here's my example Coffeescript require 'nodeunit' test = true test2 = false exports.testSomething = (test) -> …
Brian Renzenbrink
  • 145
  • 1
  • 1
  • 9
6
votes
0 answers

Code Coverage for Istanbul Wrong when using Sandbox in Nodeunit

I have written a bunch of tests using nodeunit to test my code. In doing so I wanted to mock out modules being required by the code under test. Instead of changing the code to make it more easily testable with mocks, inversion of control, when it…
Erock 634
  • 591
  • 3
  • 18
6
votes
1 answer

run one test by name from one nodeunit file

Is it possible to run only one test from nodeunit test file with several tests. My tests.js file: module.exports = { test2: function (test) { console.log ("test2") test.done(); }, test1: function (test) { …
Maxim Yefremov
  • 13,671
  • 27
  • 117
  • 166
6
votes
5 answers

Assertions library for node.js?

Assertions provided by node.js assert for unit-testing are very limited. Even before I've written the first test I was already creating a few of assertions as it was clear I will keep re-using them. Could you recommend some good library of…
esp
  • 7,314
  • 6
  • 49
  • 79
5
votes
2 answers

TravisCI is not failing my build when tests fail

I have tests written in JavaScript and I use TravisCI for tests. Setup My package.json is something like: "scripts": { "test": "node testsRunner.js" } And my .travis.yml is: language: node_js node_js: - '0.12.7' 'testsRunner.js' is: var nodeunit…
Andry
  • 16,172
  • 27
  • 138
  • 246
4
votes
4 answers

Possible to tell nodeunit not to finish a particular test until test.done() is called?

I am doing some async testing with nodeunit and I was wondering whether it is possible to tell nodeunit to not terminate test cases until test.done is called. Basically this is how my test cases looks like right now: exports.basic = testCase({ …
xjq233p_1
  • 7,810
  • 11
  • 61
  • 107
4
votes
1 answer

How to add custom assertions in Nodeunit

Is there a way of adding custom assertions to the NodeUnit test object that gets passed to each test? I'd like to do something like: var Test = require('nodeunit').Test; Test.prototype.customAssertion = function(obj) { test.same(obj.foo, 'bar'); …
evilcelery
  • 15,941
  • 8
  • 42
  • 54
4
votes
0 answers

tearDown() that is only executed after ALL tests have run?

I'm trying to write some integration tests in NodeUnit. My tests work fine, but the test runner hangs because knex is keeping a PostgreSQL DB connection open. I can get it to release by calling knex.destroy() in my tearDown, but unfortunately then…
George Armhold
  • 30,824
  • 50
  • 153
  • 232
1
2 3 4 5 6 7