【问题标题】:Jasmine-node tests executed twiceJasmine 节点测试执行了两次
【发布时间】:2015-04-26 17:56:53
【问题描述】:

我的 jasmine-node 测试执行了两次。

我从 Grunt 任务和 Jasmine 命令运行这些测试。结果是一样的,我的测试运行了两次。 我的 package.json :

{
  "name": "test",
  "version": "0.0.0",
  "dependencies": {
    "express": "4.x",
    "mongodb": "~2.0"
  },
  "devDependencies": {
    "grunt": "~0.4.5",
    "grunt-jasmine-node":"~0.3.1 "
  }
}

这是我的 Gruntfile.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

你有什么想法吗?

【问题讨论】:

  • 你的问题解决了吗?
  • 你好,很遗憾没有,然后我转移到摩卡测试

标签: node.js tdd jasmine jasmine-node


【解决方案1】:

感谢1.618。他在这里回答了这个问题:grunt jasmine-node tests are running twice

这看起来像是一些错误的行为。快速解决方法是在您的Gruntfile 中配置jasmine_node,如下所示:

jasmine_node: {
    options: {
        forceExit: true,
        host: 'http://localhost:' + port + '/',
        match: '.',
        matchall: false,
        extensions: 'js',
        specNameMatcher: '[sS]pec'
    },
    all: []
}

关键是all 参数。 grunt 插件正在寻找名称中带有 spec 的文件。出于某种原因,它会在spec/ 目录 中查找其他任何地方。如果您指定spec 目录,它的文件会被拾取两次。如果您不指定,它只会设置一次,但是您不能将 spec 放入任何非测试文件名中。

【讨论】:

    猜你喜欢
    • 2015-07-19
    • 1970-01-01
    • 2016-06-13
    • 2017-01-11
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-24
    相关资源
    最近更新 更多