我已經廣泛搜索過這個問題,沒有發現我修正了它。我試圖用webpack運行一個茉莉花測試。我試圖按照Angular網站上的教程,但它不是真正正確或完整。TS2304:在Webpack/Angular中找不到'describe'名稱2
這裏是我試過到目前爲止:
- 安裝茉莉花類型,它們存在於我的node_modules/@類型/茉莉
- 新增
"types": ["jasmine"]
我tsconfig.json即使你不這樣做需要做的是,在打字稿2.0.X - 新增
"typeRoots": ["./node_modules/@types"]
我tsconfig.json即使你沒有這樣做,在打字稿2.0.X - 新增
import {} from 'jasmine';
我的單元測試如下所述:Angular 2 Unit Tests: Cannot find name 'describe'
在這一點上,感覺就像我離開了基地,還有其他事情要發生在這裏。我正在使用awesome-typescript-loader,也許它找不到類型?
我使用的版本2.0.9的打字稿,而我的配置文件如下:
webpack.test.ts
var webpack = require('webpack');
var helpers = require('./helpers');
module.exports = {
devtool: 'inline-source-map',
resolve: {
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.ts$/,
loaders: [
{
loader: 'awesome-typescript-loader',
options: { configFileName: helpers.root('tsconfig.json') }
} , 'angular2-template-loader'
]
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'null-loader'
},
{
test: /\.css$/,
exclude: helpers.root('src', 'app'),
loader: 'null-loader'
},
{
test: /\.css$/,
include: helpers.root('src', 'app'),
loader: 'raw-loader'
}
]
},
plugins: [
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
helpers.root('./src'), // location of your src
{} // a map of your routes
)
]
}
tsconfig.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2015",
"dom"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
編輯:我用來運行測試的命令:karma start ./config/karma.conf.js --single-run
你正在使用哪個命令來運行測試? –
好問題,更新了問題,它是:業力開始./config/karma.conf.js --single-run –