問題描述
我有很多 Jasmine 單元測試,它們正在運行 Javascript 代碼的單元測試.他們正在使用 Jasmine-jquery 插件來進行 DOM 操作.他們使用 loadFixture 來加載 HTML 的固定裝置
I have lots of Jasmine unit tests, that are running unit tests for Javascripts code. They are using Jasmine-jquery plugin to do DOM manipulation. they use loadFixture, to load fixtures of HTML
我嘗試使用 JsTestDriver 和 JasmineAdapter 自動化這些單元測試但是所有涉及 DOM-jquery 操作的測試都沒有通過?這有什么問題嗎?有沒有辦法將 Jasmine-jquery 與 JsTestDriver 一起使用?
I tried to automate those unit tests, using JsTestDriver, with JasmineAdapter But all tests involve DOM-jquery manipulation are not passing? Is there something wrong with that? Is there a way to use Jasmine-jquery with JsTestDriver?
推薦答案
我會回答自己,因為我找到了解決這個問題的方法.問題是 Jasmine-Jquery 正在使用 ajax 加載 html 夾具,并且它使用相對路徑,假設(shè) html 夾具位于相對于運行 Jasmine 測試的 HTML 容器的某個位置.但是因為 JsTestDriver 將測試加載到它自己的空間"中,所以我們必須更改 Jasmine-Jquery 查找這些 html 夾具的位置,并讓 JsTestDriver 加載它們.
I will answer myself because I found a solution for this problem. The problem was Jasmine-Jquery is using ajax to load the html fixture, and it uses a relative path, assuming the html fixtures are located in somewhere relative to the HTML container that is running Jasmine tests. but because JsTestDriver is loading the tests inside its own "space", so we have to change the location, where Jasmine-Jquery looks for those html fixtures, and make JsTestDriver load them.
所以解決方法如下:
JsTestDriver 具有加載靜態(tài) html 文件的能力.在配置文件中添加以下內(nèi)容:
JsTestDriver has the ability to load static html files. in config file add the following:
服務(wù):-例如:服務(wù):- 固定裝置*.html
Serve: - for example: Serve: - fixtures*.html
現(xiàn)在您可以使用以下格式訪問那些http:localhost:9876/test/fixtures/...你讓 Jasmine-jquery 知道從這個位置加載燈具.
now you can access those with the following format http:localhost:9876/test/fixtures/... you let Jasmine-jquery knows to load the fixtures from this location.
瞧,您的測試將再次運行.
and voila, you will have your tests working again.
這篇關(guān)于Javascript JsTestDriver Jasmine &茉莉花jquery的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!