Javascript オブジェクト コンストラクターで次のメソッドが呼び出されるかどうかをテストしたいと思います。Jasmine のドキュメントで見たものから、コンストラクター メソッドをスパイでき、オブジェクトがインスタンス化された後にメソッドをスパイできますが、オブジェクトが構築される前にメソッドをスパイすることはできないようです。
オブジェクト:
Klass = function() {
this.called_method();
};
Klass.prototype.called_method = function() {
//method to be called in the constructor.
}
仕様で次のようなことをしたい:
it('should spy on a method call within the constructor', function() {
spyOn(window, 'Klass');
var obj = new Klass();
expect(window.Klass.called_method).toHaveBeenCalled();
});