Jasmine+Sinon.jsを使ってAlertが正しいテキストで表示されることを確認する
confirmでも同じように使えました。
// Spec describe("MyAlertTest", function(){ beforeEach(function(){ setFixtures(sandbox()); $("#sandbox").append("<button id='testBtn' value='test' />"); this.alertSpy = sinon.stub(window, "alert").returns(true); }); //これなしだとTypeError: Attempted to wrap alert which is already wrappedエラーが発生 afterEach(function(){ window.alert.restore(); }); it("should tell you it is clicked", function(){ $("#testBtn").click(); expect(this.alertSpy).toHaveBeenCalledWith("it is clicked!"); }); });