我有以下目录结构:
我有一个webpack + jasmine + karma Angular 2 app。应用程序在运行时工作正常,但是当我尝试运行测试npm test
时,我收到以下错误:
WARNING in ./src \.spec\.ts$
Module not found: Error: Cannot resolve module 'ts' in /Users/mateo/Desktop/app/client/src
@ ./src \.spec\.ts$
这是我的webpack.test.js
'use strict';
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: 'inline-source-map',
module: {
preLoaders: [
{ exclude: /node_modules/, loader: 'tslint', test: /\.ts$/ }
],
loaders: [
{ loader: 'raw', test: /\.(css|html)$/ },
{ exclude: /node_modules/, loader: 'ts', test: /\.ts$/ }
]
},
resolve: {
extensions: ['', '.js', '.ts'],
modulesDirectories: ['node_modules'],
root: path.resolve('.', 'src')
},
tslint: {
emitErrors: true
}
};
我只有一个测试:
这是文件的外观:
import {
TestBed
} from '@angular/core/testing';
import {
ReactiveFormsModule
} from '@angular/forms';
import {MessagesComponent} from "./messages.component";
describe('Component: MessagesComponent', () => {
let component: MessagesComponent;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [MessagesComponent],
imports: [ReactiveFormsModule]
});
const fixture = TestBed.createComponent(MessagesComponent);
component = fixture.componentInstance;
});
it('should have a defined component', () => {
expect(2 === 2).toBeTruthy();
});
});