Mocha: --require expect.js doesn't work

Created on 20 Mar 2013  路  7Comments  路  Source: mochajs/mocha

hi, so when i include expect.js over the --require parameter, it doesn't work. i also tried putting this option on mocha.opts
--require expect.js
but i still getting "ReferenceError: expect is not defined"
does --require only work with should.js? or what do i missing?

Most helpful comment

the --require option doesn't inject/define variable(s) for you. what the --require option does for you is (excuse the crude example):

require('expect');
[ your code here ]

not:

var expect = require('expect');
[ your code here ]

All 7 comments

the --require option doesn't inject/define variable(s) for you. what the --require option does for you is (excuse the crude example):

require('expect');
[ your code here ]

not:

var expect = require('expect');
[ your code here ]

so, what would it be good for? except for including "should.js" on the tests

it's not good for much other than should really haha, I would remove it now if people weren't already using it

This works for me (in node):

// inject.js
global.expect = require('expect.js');
// test/some_test.js
describe('foo', function(){
  it('should be foo', function(){
    expect('foo').to.be('foo');
  });
});
mocha --require "./inject" "test/some_test.js"

This allows me to use the same test in browsers using the _expect_ package of _bower_, which provides only a expect function within the global namespace.

Thank you @schnittstabil.

Thank you @schnittstabil :cake:

@schnittstabil where is the inject script called? Does mocha have an option for passing scripts? I thought it was only Mocha.opts. Feel free to tell me to RTFM if it is in there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  32Comments

stevemao picture stevemao  路  46Comments

sagiegurari picture sagiegurari  路  61Comments

haraldrudell picture haraldrudell  路  52Comments

moll picture moll  路  46Comments