3

I've searched this issue extensively and nothing I found has fixed it. I'm trying to use webpack to run a single jasmine test. I attempted to follow the tutorial on the Angular website but it's...not really correct or complete.

Here's what I've tried so far:

  • Installed Jasmine types, they are present in my node_modules/@types/jasmine
  • Added "types": ["jasmine"] to my tsconfig.json even though you don't have to do that in Typescript 2.0.X
  • Added "typeRoots": ["./node_modules/@types"] to my tsconfig.json even though you don't have to do that in Typescript 2.0.X
  • Added import {} from 'jasmine'; to my unit tests as described here: Angular 2 Unit Tests: Cannot find name 'describe'

At that point it felt like I was way off base, something else has to be going on here. I'm using awesome-typescript-loader, maybe it can't figure out types?

I'm using the 2.0.9 version of typescript, and my config files are as follows:

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
  }
}

EDIT: Command I'm using to run the test: karma start ./config/karma.conf.js --single-run

Community
  • 1
  • 1
Rob Louie
  • 2,462
  • 1
  • 19
  • 24

2 Answers2

5

Ugh...I found it. As I said in my post I'm using typescript 2.0.9, but the latest version of @types/jasmine uses keyof, which is a features of typescript 2.1... :/

I reverted @types/jasmine to 2.5.41 and everything is fine.

Rob Louie
  • 2,462
  • 1
  • 19
  • 24
1

I installed an older version of jasmine with this command:

npm install --save-dev @types/jasmine@2.5.41

and the problem solved.

Community
  • 1
  • 1