如何将 (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)
编辑 :问同样问题的另一种方式:我如何让 testacular 服务于 html 而不会炸毁测试运行器?
正如我上面提到的,我需要在配置中包含“test/fixtures/*.html”,但测试运行器会爆炸。
最佳答案
当前版本的 testacularjs 不能支持这个。
但是,testacularjs(Vojta Jina) 的作者建议我使用代理解决方案通过不同的 Web 服务器提供 html 来解决此问题。对于那些好奇的人,这里是完成这项工作的端到端步骤。
python -m SimpleHTTPServer 3502 &
Now you should be able to visit [http://localhost:3502/test/fixtures/first.html] and see the markup when you inspect page source
proxies = {
'/fixtures' : 'http://localhost:3502/'
};
beforeEach(function(){
jasmine.getFixtures().fixturesPath = '/fixtures/test/fixtures';
});
现在您应该可以加载 fixture/读取 fixture 了
关于unit-testing - 将 html 与 testacularjs 集成时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13019215/