Javascript JsTestDriver Jasmine&茉莉的jQuery [英] Javascript JsTestDriver Jasmine & Jasmine-jquery

查看:135
本文介绍了Javascript JsTestDriver Jasmine&茉莉的jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多Jasmine单元测试,它们运行Javascripts代码的单元测试。
他们使用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操作不通过?
这有什么问题吗?
有没有办法在JsTestDriver中使用Jasmine-jquery?

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 fixture,它使用相对路径,假设html fixture位于相对于运行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能够加载静态html文件。配置文件中的
添加以下内容:

JsTestDriver has the ability to load static html files. in config file add the following:

服务:
-
例如:
服务:
- fixtures * .html

Serve: - for example: Serve: - fixtures*.html

现在你可以使用以下格式访问那些:
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.

这篇关于Javascript JsTestDriver Jasmine&茉莉的jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆