Node.js Jasmine节点测试执行了两次
我的jasmine节点测试执行两次 我从Grunt任务和Jasmine命令运行这些测试。结果是一样的,我的测试运行了两次。 My package.json:Node.js Jasmine节点测试执行了两次,node.js,tdd,jasmine,jasmine-node,Node.js,Tdd,Jasmine,Jasmine Node,我的jasmine节点测试执行两次 我从Grunt任务和Jasmine命令运行这些测试。结果是一样的,我的测试运行了两次。 My package.json: { "name": "test", "version": "0.0.0", "dependencies": { "express": "4.x", "mongodb": "~2.0" }, "devDependencies": { "grunt": "~0.4.5", "grunt-jas
{
"name": "test",
"version": "0.0.0",
"dependencies": {
"express": "4.x",
"mongodb": "~2.0"
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-jasmine-node":"~0.3.1 "
}
}
以下是我的Grunfile.js摘录:
grunt.initConfig({
jasmine_node: {
options: {
forceExit: true,
match: '.',
matchall: true,
extensions: 'js',
specNameMatcher: 'spec'
},
all: ['test/']
}
});
grunt.loadNpmTasks('grunt-jasmine-node');
grunt.registerTask('jasmine', 'jasmine_node');
我的一个测试文件:
describe("Configuration setup", function() {
it("should load local configurations", function(next) {
var config = require('../config')();
expect(config.mode).toBe('local');
next();
});
it("should load staging configurations", function(next) {
var config = require('../config')('staging');
expect(config.mode).toBe('staging');
next();
});
it("should load production configurations", function(next) {
var config = require('../config')('production');
expect(config.mode).toBe('production');
next();
});
});
我有4个断言的2个测试文件
以下是我的提示:
grunt jasmine
Running "jasmine_node:all" (jasmine_node) task
........
Finished in 1.781 seconds
8 tests, 8 assertions, 0 failures, 0 skipped
你有什么想法吗?都归功于你。他在这里回答了这个问题:
这看起来像是有问题的行为。快速修复方法是在grunfile
中配置jasmine\u节点
,如下所示:
jasmine_node: {
options: {
forceExit: true,
host: 'http://localhost:' + port + '/',
match: '.',
matchall: false,
extensions: 'js',
specNameMatcher: '[sS]pec'
},
all: []
}
关键是
all
参数。grunt
插件正在查找名称中包含spec的文件。出于某种原因,它会出现在spec/
目录和其他任何地方。如果指定spec
目录,其文件将被拾取两次。如果您不指定,它只设置一次,但是您不能将spec放入任何非测试文件名中。您的问题解决了吗?您好,很遗憾没有,然后我转到了mocha test