Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Using Assertion Libs #37

Closed
getdave opened this issue Sep 24, 2013 · 1 comment
Closed

Using Assertion Libs #37

getdave opened this issue Sep 24, 2013 · 1 comment

Comments

@getdave
Copy link

getdave commented Sep 24, 2013

I'm attempting to add tests to my Grunt plugin. I want to use Mocha and Chai.

I've added simple mocha and installed chai from npm. initConfig is

simplemocha: {
        options: {
            globals: ['chai']
        },

        all: { 
            src: [
              'node_modules/chai/lib/chai.js',
              'test/**/*.js'
            ] 
        }
    }

I have test.js with content as per

'use strict';

var assert = require("chai");

describe('Array', function(){
  describe('#indexOf()', function(){
    it('should return -1 when the value is not present', function(){
      assert.equal(-1, [1,2,3].indexOf(5));
      assert.equal(-1, [1,2,3].indexOf(0));
    })
  })
});

...which is an example provided on the Chai website. I get the error

TypeError: Object #<Object> has no method 'equal'

Am I configuring things incorrectly?

@getdave
Copy link
Author

getdave commented Sep 25, 2013

Ended up resolving this myself.

First you require "chai" then you set "assert" variable to be equal to chai.assert.

'use strict';

var chai = require("chai");
var assert = chai.assert;


describe('Array', function(){
  describe('#indexOf()', function(){
    it('should return -1 when the value is not present', function(){
      assert.equal(-1, [1,2,3].indexOf(5));
      assert.equal(-1, [1,2,3].indexOf(0));
    })
  })
});

Apologies for wasting time here.

@getdave getdave closed this as completed Sep 25, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant