Jasmine - 错误:jasmine-fixture需要在window.jQuery或window中定义jQuery。$

时间:2016-10-25 18:34:48

标签: javascript jasmine jasmine-jquery

我正在学习并尝试使用Jasmine框架测试我的javascript。 我的javascript只是将textarea的占位符属性设置为空白。

function clearPlaceholderTextOnFocus(i) {
    i.placeholder = '';
}

我在textarea的onClick事件上调用此函数。 我在Jasmine spec中写下了以下代码 -

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('');
});

});

当我通过双击SpecRunner.html运行此代码时,我收到以下错误 -

错误:jasmine-fixture需要在window.jQuery或window。$

中定义jQuery

以下是我的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>

我的规范代码有什么问题?或者我是否需要任何其他设置来运行它?

更新 - 包括

1 个答案:

答案 0 :(得分:-1)

您是否在SpecRunner.html中导入了Jquery?喜欢这个

&#13;
&#13;
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/core.js"></script>
&#13;
&#13;
&#13;