Ste*_*las 4 javascript unit-testing jquery-mobile jasmine
我正在为我正在研究的jQuery移动应用程序实现一些Jasmine测试,我遇到了一个错误,我设法追踪到添加jQuery移动库,错误如下:
Jasmine.js:1769 TypeError: Cannot read property 'abort' of undefined.
Run Code Online (Sandbox Code Playgroud)
一旦我删除了jQM依赖项,错误就会消失.
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>HTML5/Common/Tests</title>
<!-- LOAD STYLES FIRST -->
<link type="text/css" rel="stylesheet" href="libs/jasmine.css" media="screen">
<link type="text/css" rel="stylesheet" href="../../Common/libs/jquery.mobile-1.0.1.css" />
<!-- LOAD JASMINE LIBRARIES -->
<script type="text/javascript" src="libs/jasmine.js"></script>
<script type="text/javascript" src="libs/jasmine-html.js"></script>
<!-- LOAD DEPENDENCIES -->
<script type="text/javascript" src="../../Common/libs/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../../Common/libs/jquery.mobile-1.0.1.min.js"></script>
<!-- LOAD CODE TO TEST -->
<script type="text/javascript" src="../../Common/libs/myLib.js"></script>
<!-- LOAD ACTUAL TESTS -->
<script type="text/javascript">
describe("Suite 1", function() {
it("Should be that 1 equals 0", function() {
expect(0).toEqual(1);
});
});
</script>
</head>
<body>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我更喜欢将Jasmine用于此应用程序而不是qUnit,因为我认为它更灵活,更容易在CI中实现并向BA和PM解释..但是在修补这个问题几个小时之后和一些徒劳的搜索谷歌我仍然无法解决它所以我开始考虑继续前进.
在我做之前,有没有人遇到过同样的问题并找到了解决方案呢?
感谢致敬.
3月20日更新:
门票在github Jasmine项目中:
小智 9
我能够使用jasmine-jquery对jquery移动脚本进行jasmine测试.
诀窍是你需要在DOMready上禁用jquery移动增强功能,因为它会尝试增强jasmine runner的html.您可以使用插入html runner文件头部的脚本来完成此操作:
<script type="text/javascript">
$(document).bind("mobileinit", function(){
$.mobile.autoInitializePage = false;
});
</script>
Run Code Online (Sandbox Code Playgroud)
然后你需要在从你的fixture(jasmine-jquery functionnality)插入的html上触发jquery mobile的增强:
describe('my test', function(){
beforeEach(function() {
loadFixtures("fixtures/MYFixture.html");
$("#jasmine-fixtures").attr("data-role","page").trigger("create");
}
it( ...
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1680 次 |
| 最近记录: |