当我需要Jasmine规格中的spy.js和mock-ajax.js文件时如何从Gulpfile.js运行Jasmine规格

时间:2018-10-18 07:44:08

标签: unit-testing gulp jasmine jasmine-jquery gulp-jasmine

我的文件夹结构如下:

Root
|- Scripts
    |- ViewScripts
        |- Feature_1
            |- feature_1.js
    |- Jasmine
        |- Helpers
            |- jasmine.js
            |- Spy.js
            |- mock-ajax.js
            |- jasmine-jquery.js
|- Tests
    |- Feature_1_Tests
        |- feature_1.tests.js
|- chutzpah.json
|- gulpfile.js
|- package.json
chutzpah.json 的内容是:

{   "Framework": "jasmine",   "References": [
    { "Path": "Scripts/jquery-1.10.2.js" },
    { "Path": "Scripts/Jasmine/Helpers/jasmine.js" },
    { "Path": "Scripts/Jasmine/Helpers/jasmine-html.js" },
    { "Path": "Scripts/Jasmine/Helpers/boot.js" },
    { "Path": "Scripts/Jasmine/Helpers/mock-ajax.js" },
    { "Path": "Scripts/Jasmine/Helpers/Spy.js" },
    { "Path": "Scripts/Jasmine/Helpers/jasmine-jquery.js" }   ] }

gulpfile.js 的内容是:

const gulp = require('gulp');
const jasmine = require('gulp-jasmine');

gulp.task('tests', () => 
    gulp
        .src('Tests/**/*.tests.js')
        .pipe(jasmine())
);

package.json 文件的内容为:

{
  "name": "myapp",
  "version": "1.0.0",
  "description": "",
  "main": "",
  "scripts": {
    "test": "gulp tests"
  },
  "author": "Jai Kumar",
  "license": "ISC",
  "devDependencies": {
    "gulp": "^4.0.0",
    "gulp-jasmine": "^4.0.0"
  }
}

当我从 cmd 执行 gulp测试时:

  1. 所有测试用例均失败。
  2. 我看到每个测试用例都有以下错误- ReferenceError 未定义functionNameWhichIHaveSpyOn
  3. 所有测试用例都运行失败后,cmd底部的消息就会出现插件“ gulp-jasmine”中的错误

但是当我在Visual Studio Test Explorer中使用chutzpah运行相同的测试用例时,所有测试用例都通过了。

请帮助我解决这个问题。 预先感谢。

0 个答案:

没有答案