0

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?

Community
  • 1
  • 1
philippe_b
  • 38,730
  • 7
  • 57
  • 59
  • possible duplicate of [Overriding functions in other modules in node.js](http://stackoverflow.com/questions/12968153/overriding-functions-in-other-modules-in-node-js) – Paul Sweatte Oct 02 '14 at 21:03
  • I don't think so. If it is, someone still needs to explain me how to make use of the solution :) – philippe_b Oct 03 '14 at 12:23

0 Answers0