失去了我仅剩的一点头发......
我的测试从未运行。 Browserify 似乎将所有内容都捆绑在一起,但然后什么也没有发生。
karma.config.js:
module.exports = function (config) {
config.set({
basePath: './',
frameworks: ['jasmine', 'browserify'],
files: [
"./app/main.js",
{pattern: './app/**/*.js', included: false},
{pattern: './app/**/*.spec.js', included: false},
{pattern: './node_modules/angular/angular.js', included: false},
{pattern: './node_modules/angular-mocks/angular-mocks.js', included: false},
],
exclude: [
],
browserify: {
debug: true
},
preprocessors: {
"./app/**/*.js": ["browserify"]
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: false,
browsers: [
"Chrome"
],
singleRun: true,
concurrency: Infinity
})
}
main.js:
require('angular');
var app = angular.module('app', []);
require ("./+filters");
require ("./+services");
require ("./+directives");
require ("./+controllers");
时间.spec.js:
"use strict";
var angular = require("angular");
var mocks = require("angular-mocks");
describe("The Time Service", () => {
var timeService;
beforeEach (module("app"));
beforeEach (
inject(["TimeService", (_timeService_) => {
timeService = _timeService_;
}])
);
it("should be 12:00", () => {
expect(timeService.get()).toBe("12:00");
});
});
文件夹结构如下所示:
+
| .babelrc
| .gitignore
| app.js
| favicon.ico
| gulpfile.js
| karma.conf.js
| package.json
| readme.md
| test.config.js
| tree.txt
|
+---app
| | main.js
| |
| +---+controllers
| | | index.js
| | |
| | \---main
| | main.e2e.js
| | main.js
| | main.spec.js
| |
| +---+directives
| | | index.js
| | |
| | \---about
| | about.js
| | about.scss
| |
| +---+filters
| | | index.js
| | |
| | \---reverse
| | reverse.js
| | reverse.specx.js
| |
| \---+services
| | index.js
| |
| \---time
| time.js
| time.spec.js
|
任何指示都感激地接受。
TIA, 杰夫
最佳答案
我认为您可能需要首先浏览 bundle ,然后浏览规范文件:
preprocessors: {
'app/main.js': [ 'browserify' ],
'app/**/*.spec.js': [ 'browserify' ]
},
这就是我的设置方式,它似乎对我有用。
关于javascript - 测试无法使用 Karma、Browserify、Angular 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37791108/