我正试图编写一个使用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");
});
});
然而,import语句有一个红色的波浪线,并显示错误消息“无法解析外部模块../../../scripts/typings/jasmine/jasmine,模块不能别名为非模块类型”。
您有什么想法是什么导致了这个错误?我已经检查了我的项目构建设置中的“模块系统”选项是否设置为AMD。我还检查了jasmine.d.ts中是否定义了jasmine模块。我从DefinitelyTyped网站下载了这个文件。
declare module jasmine {
...
}
import Jasmine from 'path/here';
. es5:var Jasmine = require('path/here');
. 请使用beforeEach
、it
和expect
,而不是BeforeEach
、It
和Expect
。 - marcel