将html与testacularjs集成时出错 [英] Error while integrating html with testacularjs
问题描述
如何整合(html)灯具与testacular?是否有任何建议执行基于DOM的测试或者是反模式?
How do I integrate (html) fixtures with testacular? Is there any recommendation for performing DOM based tests or is it an anti-pattern?
目标:我试图测试一个自定义模块,它解析DOM树并创建一个新数据结构。 DOM树可以是动态的(像html / markdown编辑器的内容),因此不是端到端测试的好候选。
Objective : I am trying to test a custom module which parses the DOM tree and creates a new data structure. The DOM tree can be dynamic (like contents of a html/markdown editor) and hence is not a good candidate for end to end testing
问题:我试图使用jasmine-jquery为这个DOM测试和在我的testacular.conf.js,我有部分允许加载html文件到浏览器。
Problem : I am trying to use jasmine-jquery for this DOM testing and in my testacular.conf.js, I have the section to allow loading of html files into the browser.
// 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夹具(即使在我写任何茉莉花jquery代码加载灯具之前):
However in my test runner on the command line, I get the following error message when I drop the html fixture(even before I write any jasmine-jquery code to load the 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)
EDIT :另一种提出同样问题的方法:如何获得testacular提供html,
EDIT : Another way to ask the same question : How do I get testacular to serve html and not blow up the test runner?
如上所述,我需要在配置中包含test / fixtures / *。html,但是测试运行器只是炸开了。
As I mentioned above, I need to include the 'test/fixtures/*.html" in the config but the test runner just blows up.
推荐答案
当前版本的testacularjs不能支持
但是,testacularjs(Vojta Jina)使用代理解决方案来解决这个问题,通过不同的网络服务器提供html。对于那些好奇,这里是端到端的步骤,让这个工作。
Current version of testacularjs cannot support this. However, the author of testacularjs(Vojta Jina), suggested I use a proxy solution to workaround this by serving the html through a different web server. For those curious, here are the end to end steps to get this working.
-
首先通过运行如下命令运行webserver
First run the webserver by running a command like the following
python -m SimpleHTTPServer 3502& p>
python -m SimpleHTTPServer 3502 &
将夹具文件放在适当的位置。 Mine was test / fixtures / first.html
Drop your fixture file(s) in appropriate location. Mine was test/fixtures/first.html
现在你应该可以访问[http:// localhost:3502 / test / fixtures /first.html]并在检查网页源时查看标记
Now you should be able to visit [http://localhost:3502/test/fixtures/first.html] and see the markup when you inspect page source
编辑testacular.conf.js以添加配置
Edit testacular.conf.js to add the config block
proxies = {
'/fixtures' : 'http://localhost:3502/'
};
编辑您的茉莉花单元测试,以获得类似以下的块:
Edit your jasmine unit test to have a block like the following
beforeEach(function(){
jasmine.getFixtures().fixturesPath = '/fixtures/test/fixtures';
});
现在你应该可以加载/ readfixture
Now you should be in a position to loadfixture/readfixture
这篇关于将html与testacularjs集成时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!