久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 Jasmine 和 TypeScript 進行單元測試

Unit testing using Jasmine and TypeScript(使用 Jasmine 和 TypeScript 進行單元測試)
本文介紹了使用 Jasmine 和 TypeScript 進行單元測試的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試使用 Jasmine 編譯一個用 Typescript 編寫的單元測試.在我的單元測試文件中包含以下內容后,Resharper 會提示我一個從 jasmine.d.ts 導入類型的鏈接.

I am trying to get a unit test written in Typescript using Jasmine to compile. With the following in my unit-test file, Resharper prompts me with a link to import types from 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 調用添加了前綴):

So I click on the link and end up with the following (actually resharper only prefixed the describe function with "Jasmine.", so I manually prefixed the other Jasmine calls):

/// <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.模塊不能別名為非模塊類型"

However the import statement has a red squiggly line with error message "Unable to resolve external module ../../../scripts/typings/jasmine/jasmine. Module cannot be aliased to a non-module type"

知道是什么導致了這個錯誤嗎?我檢查了我的項目構建設置中的模塊系統"選項是否設置為 AMD.我還檢查了 jasmine 模塊是否在 jasmine.d.ts 中定義.我從DefiniteTyped 網站下載了這個文件.

Any idea what is causing this error? I've checked that the "Module System" option is set to AMD in my project build settings. I've also checked that the jasmine module is defined in jasmine.d.ts. I downloaded this file from DefinitelyTyped site.

declare module jasmine {
    ...
}

推薦答案

這是(在我看來)截至 2018 年測試 ts-node 應用程序的最佳方法:

Here's (in my opinion) the best way to test a ts-node app as of 2018:

npm install --save-dev typescript jasmine @types/jasmine ts-node

package.json中:

{
  "scripts": {
    "test": "ts-node node_modules/jasmine/bin/jasmine"
  }
}

jasmine.json 中將文件模式更改為 *.ts

In jasmine.json change file pattern to *.ts

"spec_files": ["**/*[sS]pec.ts"],

在您的規范文件中:

import "jasmine";
import something from "../src/something";

describe("something", () => {
    it("should work", () => {
        expect(something.works()).toBe(true);
    });
});

運行測試:

npm test

這將使用本地安裝的 ts-nodejasmine 版本.這比使用全局安裝的版本要好,因為使用本地版本,您可以確保每個人都使用相同的版本.

This will use the locally installed versions of ts-node and jasmine. This is better than using globally installed versions, because with local versions, you can be sure that everyone is using the same version.

注意:如果您有一個 Web 應用而不是節點應用,您可能應該使用 Karma 而不是 Jasmine CLI 運行測試.

Note: if you have a web app instead of a node app, you should probably run your tests using Karma instead of the Jasmine CLI.

這篇關于使用 Jasmine 和 TypeScript 進行單元測試的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認為文檔“準備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發技術
What do jasmine runs and waitsFor actually do?(jasmine 運行和等待實際上是做什么的?)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對鏈式方法進行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監視函數中的函數調用?)
主站蜘蛛池模板: 国产精品久久久久av | 黄色毛片在线观看 | 国产精品区一区二区三 | 亚洲第一黄色网 | 国产精品欧美精品日韩精品 | 美女视频网站久久 | 日韩www | 草草网| 先锋资源站 | 日韩在线观看一区 | 美日韩免费 | 一级毛片在线视频 | 国产精品一区二区久久久久 | 91社区在线观看播放 | 久草青青草 | 夜久久 | 91社区在线高清 | 国产精品视频观看 | 日韩一区二区三区视频 | 国产精品呻吟久久av凹凸 | 九一视频在线播放 | 精品国产精品国产偷麻豆 | 久久逼逼 | 日韩不卡在线 | 在线国产视频 | 国产在线精品一区二区三区 | 欧美午夜精品久久久久久浪潮 | 亚洲综合大片69999 | 久久久久国产精品人 | 91久久精品国产 | 成人精品久久 | 久久久精 | 国产在线观看一区二区 | 午夜视频在线 | 欧美αv | aaa精品 | 精品国产高清一区二区三区 | 红桃成人在线 | 中文字幕99 | 精品99在线 | 人人擦人人干 |