2017-03-08 146 views
1

我已經廣泛搜索過這個問題,沒有發現我修正了它。我試圖用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

+0

你正在使用哪個命令來運行測試? –

+0

好問題,更新了問題,它是:業力開始./config/karma.conf.js --single-run –

回答

2

呃...我找到了。正如我在我的帖子中說的,我使用的是typescript 2.0.9,但是@ types/jasmine的最新版本使用keyof,這是typescript 2.1的一個特性:.../

我還原了@ types/jasmine 2.5.41,一切都很好。

+0

哦,很好,有一個美好的一天:) –

+0

Angular是一個卡房子 – light24bulbs

相關問題