我的qUnit测试套件需要一些不同的全页DOM样本 [英] I need a number of different full-page DOM samples for my qUnit test suite

查看:127
本文介绍了我的qUnit测试套件需要一些不同的全页DOM样本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有少量的Javascript来测试,但是它在整个页面上运行,例如,通过编号的ID如#t34来查找元素。我需要创建一些不同的页面来测试不同的可能配置。我看到我可以使用qunit-fixture来创建一个DOM树来进行访问,但每个页面配置都需要一个完整的页面,因为它将通过id找到元素。

I have a small amount of Javascript to test, but it operates on the entire page, for example, finding elements by numbered ids like "#t34". I need to create a handful of different pages to test the different possible configurations. I see that I can use qunit-fixture to create a DOM tree for the tests to access, but each page configuration needs to be a complete page, since it will find elements by id.

各种qUnit教程似乎集中在执行简单算术的纯JavaScript函数的简单示例中。我需要帮助了解如何使用多个不同的文件构建真正的测试套件。

The various qUnit tutorials out there seem focused on the simple examples of pure Javascript functions performing simple arithmetic. I need help understanding how to build a real test suite using a number of different files.

更新了更多详细信息:我是 coverage.py ,Python代码覆盖工具。它生成HTML报告。这些报告给他们添加了一些jQuery来增加一点点的交互性。我增加了很多,并希望自动化测试。 HTML会像这样 。没有涉及到服务器,这些只是写入本地目录的文件,所以没有ajax的机会。我想对许多不同的页面配置运行我的测试,主要是针对红色和绿色的代码块的边缘情况。

Updated with more details: I'm the owner of coverage.py, the Python code coverage tool. It generates HTML reports. These reports have jQuery on them to add a little bit of interactivity. I'm adding quite a lot more, and would like to automate the testing. The HTML looks like this. There is no server involved, these are just files written to a local directory, so there is no opportunity for ajax. I would like to run my tests against a number of different page configurations, mostly to do with edge cases of red- and green-colored chunks of code.

因为我的代码以$ code> $(#t123)(例如)在同一个DOM中不能有多个HTML页面,因为ids会冲突。如何在不同的HTML页面上运行qUnit?

Because my code accesses source lines by number as $("#t123") (for example), I can't have more than one "page" of HTML in the same DOM, since the ids will conflict. How can I run qUnit against different pages of HTML?

推荐答案

#qunit-fixture会自动由QUnit重置,这意味着你可以用每个测试使用的标记填充它,或将其留空,并让每个测试填充它以利用自动休息。或者只需使用每次测试后单独重置的标记。

#qunit-fixture is automatically reset by QUnit, which means you can fill it with markup used by each test, or leave it empty and have each test fill it to leverage the auto rest. Or just use markup that you reset individually after each test.

您可以使用模块方法重构每次测试设置和拆卸:http://docs.jquery.com/QUnit/module

You can refactor per-test setup and teardown using the module method: http://docs.jquery.com/QUnit/module

在这种情况下,它听起来像对于每个测试,良好的选项将使用(同步)ajax请求,将需要的页面标记加载到#qunit-fixture元素中。这样你只需要自定义设置,因为QUnit会在以后重置。

In this case it sounds like a good option would be using (synchronous) ajax requests for each test, loading the page markup you need into the #qunit-fixture element. That way you only need custom setup, as QUnit will reset afterwards.

即使你只是从文件系统处理本地文件,只要它们在与testuite文件相同的目录,您应该可以通过ajax加载它们。

Even if you're dealing just with local files from the filesystem, as long as they are in the same directory as your testsuite file, you should be able to load them via ajax.

如果没有,它很容易让本地服务器运行,例如通过在该目录中打开 http:// localhost:8080 / & python -m SimpleHTTPServer 8080。

If not, its easy enough to get a local server running, e.g. via "open http://localhost:8080/ && python -m SimpleHTTPServer 8080" in that directory.

这篇关于我的qUnit测试套件需要一些不同的全页DOM样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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