我正在尝试从命令行运行jasmine。出于某种原因,任何和所有匹配器都无法正常工作......
这是我的test_spec.js
describe('whatever', function() {
it('whatevs', function(done) {
expect(200).toEqual(200);
done();
})
});
从命令行我运行
$ jasmine test_spec.js
这是输出
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
节点版本4.4.0
jasmine-node version 1.14.3
答案 0 :(得分:1)
使用Node.js 4.4.0,以下是我运行以使您的文件工作的命令:
npm install -g jasmine
jasmine init
jasmine test_spec.js
如果这对您不起作用,可能会有以下几种可能:
可能已跳过jasmine init
步骤或需要重新运行。
也许您的路径中有一个不同的jasmine
可执行文件在与jasmine
npm模块关联的文件之前运行。
答案 1 :(得分:0)
嘿,这里有一个全新的答案。
原来它与我的茉莉花装置无关。相反,当我使用chai和mocha时,我留下了残留的spec_helper.js文件。我把它移到spec / helpers中,所以Jasmine自动加载它。它包括诸如
之类的精彩代码global.expect = chai.expect()
这打破了我所有的茉莉花匹配者......
所以耶和华在这里没问题。我只是设置了与Jasmine相撞的全球变量!哎呀!