我正在为rails上的按钮进行jasmine测试,这会改变html dir属性。我的点击功能工作正常,但是当我运行我的测试时,我确实看到了参考错误。任何帮助或建议将受到高度赞赏。
view.html.erb
<p><%= button_tag 'Convert', remote: 'true' %></p>
convert.js
$(document).ready(function(){
$('button').on('click', function (){
$('html').attr('dir', getElement);
});
function getElement() {
return this.getAttribute('dir') === 'rtl' ? 'ltr' : 'rtl';
}
});
&#13;
这是我的茉莉花测试文件。
conversion_spec.js
//= 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;
这是我的错误消息:
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;