【发布时间】:2015-09-01 00:49:49
【问题描述】:
我正在尝试使用 Jasmine 编译一个用 Typescript 编写的单元测试。在我的单元测试文件中包含以下内容后,Resharper 会提示我一个从 jasmine.d.ts 导入类型的链接。
/// <reference path="sut.ts" />
/// <reference path="../../../scripts/typings/jasmine/jasmine.d.ts" />
describe("Person FullName", function () {
var person;
BeforeEach(function () {
person = new Person();
person.setFirstName("Joe");
person.setLastName("Smith");
});
It("should concatenate first and last names", function () {
Expect(person.getFullName()).toBe("Joe, Smith");
});
});
所以我点击链接并得到以下结果(实际上 resharper 只在 describe 函数前加上了“Jasmine.”,所以我手动为其他 Jasmine 调用添加了前缀):
/// <reference path="sut.ts" />
/// <reference path="../../../scripts/typings/jasmine/jasmine.d.ts" />
import Jasmine = require("../../../Scripts/typings/jasmine/jasmine");
Jasmine.describe("Person FullName", function () {
var person;
Jasmine.BeforeEach(function () {
person = new Person();
person.setFirstName("Joe");
person.setLastName("Smith");
});
Jasmine.It("should concatenate first and last names", function () {
Jasmine.Expect(person.getFullName()).toBe("Joe, Smith");
});
});
但是,导入语句有一条红色波浪线,带有错误消息“无法解析外部模块../../../scripts/typings/jasmine/jasmine。模块不能别名为非模块类型”
知道是什么导致了这个错误吗?我检查了我的项目构建设置中的“模块系统”选项是否设置为 AMD。我还检查了 jasmine 模块是否在 jasmine.d.ts 中定义。我从DefiniteTyped 网站下载了这个文件。
declare module jasmine {
...
}
【问题讨论】:
-
es6:
import Jasmine from 'path/here';。 es5:var Jasmine = require('path/here');。使用beforeEach、it和expect而不是BeforeEach、It和Expect。 -
感谢您的回复。我认为在打字稿中以下是有效的?进口茉莉花 = 要求(“...”)。虽然可能不是因为它给出了这么多编译错误......
标签: javascript unit-testing typescript jasmine chutzpah