dolokhov dolokhov - 5 months ago 39
Node.js Question

Jasmine node - All matchers are undefined?

hoping this one will be an easy slam dunk for someone. I'm driving myself crazy here.

I'm trying to run jasmine from the command line. For some reason any and all matchers are failing to work...

Here is my test_spec.js

describe('whatever', function() {

it('whatevs', function(done) {
expect(200).toEqual(200);
done();
})

});


From the command line I run

$ jasmine test_spec.js


And here is the output

Started
F

Failures:
1) whatever whatevs
Message:
TypeError: expect(...).toEqual is not a function
Stack:
TypeError: expect(...).toEqual is not a function
at Object.<anonymous> (/Users/dolokhov/Work/EcoEverything/supreme/test_spec.js:4:17)
at clearDB (/Users/dolokhov/Work/EcoEverything/supreme/spec/helpers/db_utils.js:21:12)
at /Users/dolokhov/Work/EcoEverything/supreme/spec/helpers/db_utils.js:29:14
at /Users/dolokhov/Work/EcoEverything/supreme/node_modules/mongoose/lib/connection.js:284:19
at open (/Users/dolokhov/Work/EcoEverything/supreme/node_modules/mongoose/lib/connection.js:511:17)
at NativeConnection.Connection.onOpen (/Users/dolokhov/Work/EcoEverything/supreme/node_modules/mongoose/lib/connection.js:521:5)
at /Users/dolokhov/Work/EcoEverything/supreme/node_modules/mongoose/lib/connection.js:483:11
at /Users/dolokhov/Work/EcoEverything/supreme/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:71:5
at /Users/dolokhov/Work/EcoEverything/supreme/node_modules/mongoose/node_modules/mongodb/lib/db.js:234:5
at connectHandler (/Users/dolokhov/Work/EcoEverything/supreme/node_modules/mongoose/node_modules/mongodb/lib/server.js:306:7)
at g (events.js:260:16)
at emitOne (events.js:77:13)

1 spec, 1 failure
Finished in 0.048 seconds


node version 4.4.0

jasmine-node version 1.14.3

Answer

Using Node.js 4.4.0, here are the commands I ran to get your file to work:

npm install -g jasmine
jasmine init
jasmine test_spec.js

If that doesn't work for you, some possibilities might be:

  • Maybe the jasmine init step was skipped or needs to be re-run.

  • Maybe there is a different jasmine executable in your path that is getting run before the one that is associated with the jasmine npm module.