philippe_b
philippe_b

Reputation: 41418

How to add custom assertions in Nodeunit for a Grunt plugin project

I'm writing a plugin for Grunt and I want to add a custom assertion to the plugin's unit tests.

I found this SO answer about adding custom assertions to NodeUnit. So I edited the test case template generated by Grunt and I wrote something like:

'use strict';

var grunt = require('grunt');
var assert = require('nodeunit').assert;

assert.isVowel = function(letter, message) {
    var vowels = [ 'a', 'e', 'i', 'o', 'u' ];

    if (vowels.indexOf(letter) === -1) {
        assert.fail(letter, vowels.toString(), message, 'is not in');
    }
};

exports.my_plugin = {
  setUp: function(done, test) {
    done();
  },
  first_test_case: function(test) {
    test.isVowel("e", 'It should be a vowel.');
    test.done();
  }
};

However, that does not work. The test case fails with TypeError: Object #<Object> has no method 'isVowel'.

I also tried to declare assert.isVowel in the setUp function, with the same result. Any idea?

Upvotes: 0

Views: 48

Answers (0)

Related Questions