我刚刚组建了一个新的快速启动项目如下角度的WebPack快速入门的使用(angular 2 webpack quickstart)角2 - TestBed.configureTestingModule - 供应商:[]抛出保留字“进口”的错误
我已经添加了我的第一次测试.spec.ts这样
describe('first test',()=>{
beforeEach(()=>{
TestBed.configureTestingModule({
providers:[MockBackend]
})
)
}
,并抛出我
SyntaxError:User of reserved word 'import'
如果我删除MockBackend它工作正常。
EDIT------------------------
I found out that if I provide e.g. MockBackend to the app.component.spec.ts (also from quickstart), everthing works fine.
So the only difference is the location of my test file which is
app
--app.component.spec
--sdk (folder)
----tests (folder)
------mytest.spec
这里是我的karma.conf,webpack.test和webpack.common(这基本上是默认的从快速入门指南
噶
var webpackConfig = require('./webpack.test');
module.exports = function (config) {
var _config = {
basePath: '',
frameworks: ['jasmine'],
files: [
{pattern: './config/karma-test-shim.js', watched: false}
],
preprocessors: {
'./config/karma-test-shim.js': ['webpack', 'sourcemap']
},
webpack: webpackConfig,
webpackMiddleware: {
stats: 'errors-only'
},
webpackServer: {
noInfo: true
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['PhantomJS'],
singleRun: true
};
config.set(_config);
};
Webpack.test
var helpers = require('./helpers');
module.exports = {
devtool: 'inline-source-map',
resolve: {
extensions: ['', '.ts', '.js']
},
module: {
loaders: [
{
test: /\.ts$/,
loaders: ['ts', 'angular2-template-loader']
},
{
test: /\.html$/,
loader: 'html'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'null'
},
{
test: /\.css$/,
exclude: helpers.root('src', 'app'),
loader: 'null'
},
{
test: /\.css$/,
include: helpers.root('src', 'app'),
loader: 'raw'
}
]
}
}
Webpack.common
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');
module.exports = {
entry: {
'polyfills': './src/polyfills.ts',
'vendor': './src/vendor.ts',
'app': './src/main.ts'
},
resolve: {
extensions: ['', '.js', '.ts']
},
module: {
loaders: [
{
test: /\.ts$/,
loaders: ['ts', 'angular2-template-loader']
},
{
test: /\.html$/,
loader: 'html'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file?name=assets/[name].[hash].[ext]'
},
{
test: /\.css$/,
exclude: helpers.root('src', 'app'),
loader: ExtractTextPlugin.extract('style', 'css?sourceMap')
},
{
test: /\.css$/,
include: helpers.root('src', 'app'),
loader: 'raw'
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ['app', 'vendor', 'polyfills']
}),
new HtmlWebpackPlugin({
template: 'src/index.html'
})
]
};
你用'import:'而不是'imports:'somewhere(例如''NgModule()') –
nope,无论它是'进口',但是如果我有提供者:[],它就可以工作。只有当我尝试提供 –
是否有遗漏你最后的评论。 “只有当我试图提供”......? –