From e534997bf9a4fbbbc4ef0465c822cf87cb997173 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 18 Nov 2014 11:42:25 -0800 Subject: [PATCH] Specs for the error handler. --- spec/atom-spec.coffee | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/spec/atom-spec.coffee b/spec/atom-spec.coffee index 615e510f7..aca2be885 100644 --- a/spec/atom-spec.coffee +++ b/spec/atom-spec.coffee @@ -52,3 +52,67 @@ describe "the `atom` global", -> it 'loads the default core config', -> expect(atom.config.get('core.excludeVcsIgnoredPaths')).toBe true expect(atom.config.get('editor.showInvisibles')).toBe false + + describe "window onerror handler", -> + beforeEach -> + spyOn atom, 'openDevTools' + spyOn atom, 'executeJavaScriptInDevTools' + + it "will open the dev tools when an error is triggered", -> + try + a + 1 + catch e + window.onerror.call(window, e.toString(), 'abc', 2, 3, e) + + expect(atom.openDevTools).toHaveBeenCalled() + expect(atom.executeJavaScriptInDevTools).toHaveBeenCalled() + + describe "::onWillThrowError", -> + willThrowSpy = null + beforeEach -> + willThrowSpy = jasmine.createSpy() + + it "is called when there is an error", -> + error = null + atom.onWillThrowError(willThrowSpy) + try + a + 1 + catch e + error = e + window.onerror.call(window, e.toString(), 'abc', 2, 3, e) + + delete willThrowSpy.mostRecentCall.args[0].preventDefault + expect(willThrowSpy).toHaveBeenCalledWith + message: error.toString() + url: 'abc' + line: 2 + column: 3 + originalError: error + + it "will not show the devtools when preventDefault() is called", -> + willThrowSpy.andCallFake (errorObject) -> errorObject.preventDefault() + atom.onWillThrowError(willThrowSpy) + + try + a + 1 + catch e + window.onerror.call(window, e.toString(), 'abc', 2, 3, e) + + expect(willThrowSpy).toHaveBeenCalled() + expect(atom.openDevTools).not.toHaveBeenCalled() + expect(atom.executeJavaScriptInDevTools).not.toHaveBeenCalled() + + describe "::onDidThrowError", -> + didThrowSpy = null + beforeEach -> + didThrowSpy = jasmine.createSpy() + + it "is called when there is an error", -> + error = null + atom.onDidThrowError(didThrowSpy) + try + a + 1 + catch e + error = e + window.onerror.call(window, e.toString(), 'abc', 2, e) + expect(didThrowSpy).toHaveBeenCalledWith(error.toString())