简体   繁体   English

使用Jasmine和ReSharper测试TypeScript模块

[英]Testing TypeScript modules with Jasmine and ReSharper

I have the following Jasmine test in a TypeScript file in a VS2017 project: 我在VS2017项目的TypeScript文件中具有以下Jasmine测试:

describe("A trivial test", () => {
  it("Should pass", () => {
    expect(true).toBeTruthy();
  });
});

This runs using the ReSharper runner, and all is well. 这可以使用ReSharper运行器运行,一切都很好。

Then I add 然后我添加

import { TestedObject } from "./TestedModule";

to the top of the file. 到文件顶部。

This time when trying to run the test, ReSharper reports: 这次,当尝试运行测试时,ReSharper报告:

Ignored: Task skipped on timeout 忽略:任务在超时时被跳过

Jasmine reports: 茉莉花报告:

No specs found 找不到规格

and opening the browser console I see: 并打开浏览器控制台,我看到:

Uncaught ReferenceError: define is not defined 未被捕获的ReferenceError:未定义

Looking at the error location I see the the transpiled TypeScript hoping to use RequireJS AMD module loading (as configured in tsconfig.json): 查看错误位置,我看到了希望使用RequireJS AMD模块加载(如tsconfig.json中配置的)的已转换TypeScript:

define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var TestedObject = (function () {
        function TestedObject() {
            this.magicNumber = 3;
        }
        return TestedObject;
    }());
    exports.TestedObject = TestedObject;
});

However, RequireJS is not loaded and so far I have not found how to load it to make it available in this scenario. 但是,尚未加载RequireJS,到目前为止,我还没有找到如何加载它以使其在这种情况下可用。

I feel this could be a one-liner (if you know which line, where) but can anyone point me in the right direction for either making RequireJS available to the tests, or an alternative setup that will allow me to use ReSharper to run the tests? 我觉得这可能是一个单行代码(如果您知道哪行,在哪里),但是任何人都可以为我指明正确的方向,以使RequireJS可以用于测试,或者可以让我使用ReSharper来运行测试?

这已作为ReSharper错误提出: https : //youtrack.jetbrains.com/issue/RSRP-465184

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM