执行jasmine测试时引用错误

时间:2015-05-21 19:57:12

标签: javascript ruby-on-rails jasmine

我正在为rails上的按钮进行jasmine测试,这会改变html dir属性。我的点击功能工作正常,但是当我运行我的测试时,我确实看到了参考错误。任何帮助或建议将受到高度赞赏。

view.html.erb

<p><%= button_tag 'Convert', remote: 'true' %></p>

convert.js

&#13;
&#13;
$(document).ready(function(){
 $('button').on('click', function (){
   $('html').attr('dir', getElement);
 });

  function getElement() {
   return this.getAttribute('dir') === 'rtl' ? 'ltr' : 'rtl';
 }
});
&#13;
&#13;
&#13;

这是我的茉莉花测试文件。

conversion_spec.js

&#13;
&#13;
//= require jquery

describe('#rtl', function (){
  describe("Testing spies", function () {
    it("Should replace the return value of function being spied on", function () {
      // Arrange
      var myApp = new getElement();
      spyOn(myApp, "getAttribute").and.returnValue('rtl');
      
      // Act
      var result = myApp.useFlagForSomething();
      
      // Assert
      expect(result).toBe("rtl");
    });
  });
});
&#13;
&#13;
&#13;

这是我的错误消息:

&#13;
&#13;
Failures:
          #rtl Testing spies Should replace the return value of function being spied on

          ReferenceError: Can't find variable: getElement in http://localhost:45463/__spec__/conversion_spec.js (line 28)
          ReferenceError: Can't find variable: getElement
    at http://localhost:45463/__spec__/conversion_spec.js:28
    at attemptSync (http://localhost:45463/__jasmine__/jasmine.js:1789)
    at http://localhost:45463/__jasmine__/jasmine.js:1777
    at http://localhost:45463/__jasmine__/jasmine.js:1762
    at http://localhost:45463/__jasmine__/jasmine.js:627
    at http://localhost:45463/__jasmine__/jasmine.js:357

1 spec, 1 failure
&#13;
&#13;
&#13;

0 个答案:

没有答案