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

如何使用 Jasmine 節點加載文件進行測試?

How to Load a File for Testing with Jasmine Node?(如何使用 Jasmine 節點加載文件進行測試?)
本文介紹了如何使用 Jasmine 節點加載文件進行測試?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一個簡單的 JavaScript 文件 color.js 和一個匹配的規范文件 colorSpec.js.

I have a simple JavaScript file, color.js, and a matching spec file, colorSpec.js.

color.js:

function Color() 
{

}

colorSpec.js:

require('./color.js');

describe("color", function() {
  it("should work", function() {
    new Color(255, 255, 255);
  });
});

當我運行 jasmine-node colorSpec.js 時,我得到以下異常:

When I run jasmine-node colorSpec.js, I get the following exception:

ReferenceError: Color is not defined

如何讓 Jasmine 在運行 colorSpec.js 之前加載我的 color.js 文件?

How can I get Jasmine to load my color.js file before running colorSpec.js?

推薦答案

您可以使用 require() 在 colorSpec.js 中加載您的 color.js.如果你不告訴茉莉花它們在你的規范文件中到底是什么,我看不出茉莉花是如何猜測所有依賴關系的.編輯 :一個快速而骯臟的解決方案,但也許有一些內置的 Jasmine 可以做到這一點:

you could load your color.js in the colorSpec.js with a require(). I dont see how jasmine can guess all the dependencies without you telling jasmine what they are exactly in your spec file. Edit : A quick and dirty solution , but maybe there is something builtin Jasmine to do that :

fs = require('fs')
myCode = fs.readFileSync('./color.js','utf-8') // depends on the file encoding
eval(myCode)

那么你的課程應該可以與 jasmine 一起使用

then your class should be available with jasmine

如果你直接在你的文件上調用 require 我認為你需要創建一個模塊并導出它

if you call require directly on your file i think you need to create a module and export it

這篇關于如何使用 Jasmine 節點加載文件進行測試?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 - 如何監視函數中的函數調用?)
主站蜘蛛池模板: 国产成人精品免费视频大全最热 | 久久夜色精品国产 | 精品一区二区三区视频在线观看 | 久久亚洲精品久久国产一区二区 | 91久久久久 | 免费a国产 | 97国产爽爽爽久久久 | 狠狠操狠狠干 | 在线观看中文字幕视频 | 久在线视频 | 一区二区三区免费 | 特级丰满少妇一级aaaa爱毛片 | 国产精品成人av | 在线欧美小视频 | www.久久久.com | 九九热在线视频 | 亚洲国产欧美在线人成 | 人人干人人干人人 | 日韩在线免费视频 | www四虎com| 久草视频观看 | 久久久日韩精品一区二区三区 | 日韩精品无码一区二区三区 | 国产视频第一页 | 一级欧美一级日韩片免费观看 | 国产精品一区一区 | 欧美在线视频一区二区 | 国产成人精品一区二区三区网站观看 | 久久久久国产成人精品亚洲午夜 | 四虎成人免费电影 | 日韩在线中文字幕 | 久久精品国内 | 天天操天天玩 | 精品国产乱码久久久久久牛牛 | 伊人久操| 久久99精品久久久久久 | 成人精品一区二区 | 国产亚洲精品a | 欧美成年黄网站色视频 | 毛片免费视频 | 日本特黄a级高清免费大片 成年人黄色小视频 |