【发布时间】:2017-03-01 11:43:41
【问题描述】:
我正在尝试使用 karma 和 webpack 测试我的指令。 这是业力配置文件
module.exports = function (config) {
config.set({
basePath: './',
frameworks: ["jasmine"],
files: [
{
pattern: 'directive.spec.ts',
watched: false
}],
exclude: [],
preprocessors: {
'directive.spec.ts': ['webpack', 'sourcemap']
},
webpackServer: {
noInfo: true
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: [
"PhantomJS"
],
singleRun: true,
reporters: ['mocha'],
webpack: {
resolve: {
extensions: ['', '.ts', '.js'],
modulesDirectories: ['node_modules', '.'],
},
module: {
loaders: [{
test: /\.ts$/,
loader: 'awesome-typescript-loader'
}]
},
stats: {
colors: true,
reasons: true
},
debug: true,
devtool: 'inline-source-map'
}
});
};
还有directive.spec.ts:
import { MyDirective } from './directive';
import {TestComponent} from './test';
import {
async,
inject,
TestBed,
} from '@angular/core/testing';
describe('TestComponent', () => {
let fixture: any;
beforeEach(() => {
fixture = TestBed.configureTestingModule({
declarations: [ TestComponent, MyDirective]
})
.createComponent(TestComponent);
fixture.detectChanges();
});
it('should work', () => {
expect(true).toBe(true);
});
但是当我尝试运行我的测试时,我收到了这个错误:
PhantomJS 2.1.1 (Mac OS X 0.0.0) 错误 ReferenceError: 找不到 变量:在directive.spec.ts:1380处映射
我在这里错过了什么?
【问题讨论】:
-
行号很大,所以我认为它会将您的导入视为文件中的内容。我怀疑
MyDirective或TestComponent在某处使用了Map变量,但没有从某处定义它或import。您可以查看这些文件中是否/在哪里引用了Map,并找出它没有从哪里导入或定义。
标签: javascript testing angular webpack karma-jasmine