use*_*559 8 continuous-integration unit-testing fixtures jasmine
如何将(html)灯具与testacular集成?有没有建议进行基于DOM的测试,还是反模式?
目标:我正在尝试测试一个解析DOM树并创建新数据结构的自定义模块.DOM树可以是动态的(如html/markdown编辑器的内容),因此不适合端到端测试
问题:我正在尝试使用jasmine-jquery进行DOM测试,在我的testacular.conf.js中,我有一节允许将html文件加载到浏览器中.
// list of files / patterns to load in the browser
files = [
JASMINE,
JASMINE_ADAPTER,
'test/spec/**/*.js',
'test/fixtures/*.html' **/* Needs to be included here to be served */**
];
但是在我的命令行测试运行器中,当我删除html fixture时(甚至在我编写任何jasmine-jquery代码来加载fixture之前),我收到以下错误消息:
Chrome 22.0 **ERROR**
Uncaught SyntaxError: Unexpected token < at /Users/myUser/myProject/test/fixtures/fixture_template.html:1 Chrome 22.0: Executed 0 of 0 ERROR (0.143 secs / 0 secs)
编辑:提出同样问题的另一种方式:我如何获得pracular服务html而不是炸毁测试运行?
正如我上面提到的,我需要在配置中包含'test/fixtures/*.html',但测试运行器只是爆炸了.
当前版本的testacularjs无法支持此功能.然而,testacularjs(Vojta Jina)的作者建议我使用代理解决方案通过不同的Web服务器提供html来解决这个问题.对于那些好奇的人来说,这里是完成这项工作的端到端步骤.
首先通过运行如下命令来运行Web服务器
python -m SimpleHTTPServer 3502&
将夹具文件放在适当的位置.我是test/fixtures/first.html
现在您应该能够访问[http:// localhost:3502/test/fixtures/first.html]并在检查页面源时看到标记
编辑testacular.conf.js以添加配置块
proxies = {
'/fixtures' : 'http://localhost:3502/'
};
Run Code Online (Sandbox Code Playgroud)编辑您的茉莉花单元测试以获得如下所示的块
beforeEach(function(){
jasmine.getFixtures().fixturesPath = '/fixtures/test/fixtures';
});
Run Code Online (Sandbox Code Playgroud)现在你应该能够加载fixture/readfixture
如http://testacular.github.com/0.6.0/config/files.html所述,自版本0.5.2起,您可以使用新的配置语法:
files = [
JASMINE,
JASMINE_ADAPTER,
'test/spec/**/*.js',
{
pattern: 'test/fixtures/*.html',
watched: true,
included: false,
served: true
}
];
Run Code Online (Sandbox Code Playgroud)
我刚尝试过,它对我来说很好.
| 归档时间: |
|
| 查看次数: |
1134 次 |
| 最近记录: |