【问题标题】:using chutzpah and jasmine with typescript and systemjs使用 chutzpah 和 jasmine 与 typescript 和 systemjs
【发布时间】:2016-05-27 20:46:03
【问题描述】:

我无法在用打字稿编写的 jasmine 单元测试中进行导入。 Chutzpah 在 import 语句上抛出一个错误——在 js 中被翻译成一个定义

import {fakeclass} from '../src/data-analysis/fakeclass';

我看到的错误是:

Error: ReferenceError: Can't find variable: define

否则测试会被发现并运行良好。

我认为它必须与 systemjs 没有被 chutzpah 加载 - 有没有推荐的设置方法?

这是我的 chutzpah.json 文件

{
  "Framework": "jasmine",
  "TestHarnessReferenceMode": "Normal",
  "TypeScriptModuleKind": "CommonJS",

  "Compile": {
  "Mode": "External",
  "Extensions": [ ".ts" ],
  "ExtensionsWithNoOutput": [ ".d.ts" ]

},
"References": [
{
  "Includes": [ "src/*.ts" ],
  "Excludes": [ "src/*.d.ts" ]
},
{
  "Path": "./jspm_packages/system.src.js",
  "IsTestFrameworkFile": true
},
{
  "Path": "./jspm_packages/system-polyfills.src.js",
  "IsTestFrameworkFile": true
},
{
  "Path": "./config.js",
  "IsTestFrameworkFile": true
}
],
"Tests": [
{
  "Includes": [ "*/test/*.ts" ],
  "Excludes": [ "*/test/*.d.ts" ]
}
]}

【问题讨论】:

  • 您肯定需要在参考部分中参考 systemJS 和您需要的任何其他库。我计划很快使用 systemJS 设置一个好的示例,但还没有机会实现它。
  • 感谢 Mathew - 尝试将 systemJS 文件添加到配置文件(见上文) - 仍然看到同样的错误
  • 你能给我一个 git repro 你所做的尝试,以便我可以测试它吗?
  • 这是一个回购 - github.com/miantosca/chutzpah-test

标签: unit-testing typescript jasmine systemjs chutzpah


【解决方案1】:

我查看了您提供给我的示例,并按照Chutzpah Angular2 sample 中的模式使其正常工作。

config.js

System.config({
  defaultJSExtensions: true,
  transpiler: "babel",
  babelOptions: {
    "optional": [
      "es7.decorators",
      "runtime"
    ]
  },
  paths: {
    "github:*": "jspm_packages/github/*",
    "npm:*": "jspm_packages/npm/*"
  },
  map: {

  }
});

chutzpah.json

{
  "Framework": "jasmine",
  "TestHarnessReferenceMode": "AMD",
  "TestHarnessLocationMode": "SettingsFileAdjacent",
  "Compile": {
    "Mode": "External",
    "Extensions": [ ".ts" ],
    "ExtensionsWithNoOutput": [ ".d.ts" ]

  },
  "References": [
    {
      "Path": "./jspm_packages/system.src.js",
      "IsTestFrameworkFile": true
    },
    {
      "Path": "./jspm_packages/system-polyfills.src.js",
      "IsTestFrameworkFile": true
    },
    {
      "Path": "./config.js",
      "IsTestFrameworkFile": true
    }

  ],
  "Tests": [
    {
      "Includes": [ "*/test/*.ts" ],
      "Excludes": [ "*/test/*.d.ts" ]
    }
  ],
   "Server": {
       "Enabled": true
    }
}

【讨论】:

    猜你喜欢
    • 2016-05-28
    • 2017-06-21
    • 1970-01-01
    • 2013-02-22
    • 2016-08-05
    • 2015-12-27
    • 2015-11-27
    • 1970-01-01
    • 2018-09-06
    相关资源
    最近更新 更多