Jasmine和Angular 2错误:找不到模块:错误:无法解析模块' ts'在/ my / path @ ./src \ .spec \ .ts $

时间:2016-11-04 19:54:45

标签: angular jasmine karma-runner karma-jasmine angular2-template

我有以下目录结构:

enter image description here

我有一个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
    }
};

我只有一个测试:

enter image description here

这是文件的外观:

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();
    });

});

0 个答案:

没有答案