我剛剛組建了一個新的快速啓動項目如下角度的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,無論它是'進口',但是如果我有提供者:[],它就可以工作。只有當我嘗試提供 –
是否有遺漏你最後的評論。 「只有當我試圖提供」......? –