Jasmine で単体テストを行う方法を学ぼうとしています。jqueryクリックイベントがトリガーされたときにメソッドが呼び出されることをテストしようとしている非常に単純な例を作成しました。私はこれを機能させることができないようです。誰か助けてくれませんか?どうもありがとう!!
次のエラーが表示されます。
ReferenceError: Butthead is not defined in http://localhost:4243/spec/buttheadSpec.js (line 11)
と
spyOn could not find an object to spy upon for responseAlert()
ここにコードがあります
function Butthead(){
}
Butthead.prototype.responseAlert = function(){
alert('You are a butthead');
}
$(document).ready(function(){
var butthead = new Butthead();
$('#myButton').click(function(){
butthead.responseAlert();
});
}
これが私の単体テストです
// Test Fixture
describe('When clicking myButton', function(){
var butthead;
// Set up
beforeEach(function(){
butthead = new Butthead();
});
// Test
it('should say Hello', function(){
spyOn(butthead, 'responseAlert');
$('#myButton').click();
expect(butthead.responseAlert).toHaveBeenCalled();
});
});