[英]Jasmine - Error: jasmine-fixture requires jQuery to be defined at window.jQuery or window.$
I am just learning and trying to test my javascript with Jasmine framework. 我只是学习并尝试使用Jasmine框架测试我的javascript。 My javascript is just setting placeholder attribute of textarea to blank.
我的JavaScript只是将textarea的占位符属性设置为空白。
function clearPlaceholderTextOnFocus(i) {
i.placeholder = '';
}
I am calling this function on onClick event of textarea. 我在textarea的onClick事件上调用此函数。 I wrote below code in Jasmine spec-
我在Jasmine规范中写了以下代码-
describe("Test suite for clearPlaceholderTextOnFocus",function(){
it("Should set placeholder to blank", function(){
var i=affix('textarea[name="message"][placeholder="write your message here..."]');
clearPlaceholderTextOnFocus(i);
var placeholderval = $('i').attr('placeholder');
expect(placeholderval).toHaveValue('');
});
});
When I run this code by double clicking on SpecRunner.html then I am getting below error - 当我通过双击SpecRunner.html运行此代码时,出现以下错误-
Error: jasmine-fixture requires jQuery to be defined at window.jQuery or window.$ 错误:茉莉花夹具需要在window.jQuery或window。$处定义jQuery。
Below is my SpecRunner.html file : 以下是我的SpecRunner.html文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Jasmine Spec Runner v2.5.2</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.5.2/jasmine_favicon.png">
<link rel="stylesheet" href="lib/jasmine-2.5.2/jasmine.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/core.js"></script>
<script src="lib/jasmine-2.5.2/jasmine.js"></script>
<script src="lib/jasmine-2.5.2/jasmine-html.js"></script>
<script src="lib/jasmine-2.5.2/boot.js"></script>
<script src="lib/jasmine-2.5.2/jasmine-jquery.js"></script>
<script src="lib/jasmine-2.5.2/jasmine-fixture.js"></script>
<!-- include source files here... -->
<script src="src/myfirst.js"></script>
<!-- include spec files here... -->
<script src="spec/myfirstSpec.js"></script>
</head>
<body>
</body>
</html>
What is wrong with my spec code? 我的规范代码有什么问题? or do i need any other setup to run this?
还是我需要任何其他设置来运行此程序?
Update - Including 更新-包括
Did you import Jquery in your SpecRunner.html? 您是否在SpecRunner.html中导入了Jquery? Like this
像这样
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/core.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.