javascript – 使用Jasmine和TypeScript进行单元测试

前端之家收集整理的这篇文章主要介绍了javascript – 使用Jasmine和TypeScript进行单元测试前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图用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只有前缀的描述功能与“茉莉花”,所以我手动前缀其他茉莉花调用):

/// <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中定义了茉莉花模块.我从DefinitelyTyped网站下载了这个文件.

declare module jasmine {
    ...
}

解决方法

对我来说,我做了如下工作:

安装打字

npm install typings --global

然后添加茉莉花的打字

typings install dt~jasmine --save --global
原文链接:https://www.f2er.com/js/154911.html

猜你在找的JavaScript相关文章