首页 文章

TS2304:在Webpack / Angular 2中找不到名称'describe'

提问于
浏览
1

我已经广泛搜索过这个问题,我发现没有修复它 . 我正在尝试使用webpack来运行单个茉莉花测试 . 我试图按照Angular网站上的教程进行操作,但它确实不正确或完整 .

这是我到目前为止所尝试的:

  • 已安装的Jasmine类型,它们存在于我的node_modules / @ types / jasmine中

  • 已将 "types": ["jasmine"] 添加到我的tsconfig.json中,即使您不必在Typescript 2.0中执行此操作.X

  • 添加了 "typeRoots": ["./node_modules/@types"] 到我的tsconfig.json,即使你不必在Typescript 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

1 回答

  • 2

    呃......我找到了 . 正如我在帖子中所说的那样,我使用的是typescript 2.0.9,但@ types / jasmine的最新版本使用 keyof ,这是typescript 2.1的功能...:/

    我将@ types / jasmine还原为2.5.41,一切都很好 .

相关问题