1 describe("Ext.Error", function() {
3 consoleWarningMsg = 'An uncaught error was raised with the following data:';
5 beforeEach(function() {
8 // mock the console to avoid logging to the real console during the tests
21 afterEach(function() {
25 describe("raising an error via Ext.Error.raise", function() {
27 describe("passing a string", function() {
29 it("should throw an error with a msg property", function() {
31 Ext.Error.raise('foo');
34 expect(err.msg).toEqual('foo');
38 it("should log a warning to the console", function() {
39 spyOn(Ext.global.console, 'warn');
41 Ext.Error.raise('foo');
44 expect(Ext.global.console.warn).toHaveBeenCalledWith(consoleWarningMsg);
47 it("should log the error object to the console", function() {
48 spyOn(Ext.global.console, 'dir').andCallFake(function(err){
49 expect(err.msg).toEqual('foo');
52 Ext.Error.raise('foo');
57 it("should do nothing when Ext.Error.ignore = true", function() {
58 spyOn(Ext.global.console, 'warn');
60 Ext.Error.ignore = true;
62 Ext.Error.raise('foo');
65 expect('Error should not have been caught').toBe(true);
67 expect(Ext.global.console.warn).not.toHaveBeenCalled();
68 Ext.Error.ignore = false;
71 it("should not throw an error if handled by Ext.Error.handle", function() {
72 spyOn(Ext.global.console, 'warn');
74 var origHandle = Ext.Error.handle;
75 Ext.Error.handle = function(err) {
76 expect(err.msg).toEqual('foo');
80 Ext.Error.raise('foo');
83 expect('Error should not have been caught').toBe(true);
85 expect(Ext.global.console.warn).not.toHaveBeenCalled();
86 Ext.Error.handle = origHandle;
90 describe("passing an object with a msg property", function() {
92 it("should throw an error with a msg property", function() {
94 Ext.Error.raise({msg: 'foo'});
97 expect(err.msg).toEqual('foo');
101 it("should log a warning to the console", function() {
102 spyOn(Ext.global.console, 'warn');
104 Ext.Error.raise({msg: 'foo'});
107 expect(Ext.global.console.warn).toHaveBeenCalledWith(consoleWarningMsg);
110 it("should log the error object to the console", function() {
111 spyOn(Ext.global.console, 'dir').andCallFake(function(err){
112 expect(err.msg).toEqual('foo');
115 Ext.Error.raise({msg: 'foo'});
120 it("should do nothing when Ext.Error.ignore = true", function() {
121 spyOn(Ext.global.console, 'warn');
123 Ext.Error.ignore = true;
125 Ext.Error.raise({msg: 'foo'});
128 expect('Error should not have been caught').toBe(true);
130 expect(Ext.global.console.warn).not.toHaveBeenCalled();
131 Ext.Error.ignore = false;
134 it("should not throw an error if handled by Ext.Error.handle", function() {
135 spyOn(Ext.global.console, 'warn');
137 var origHandle = Ext.Error.handle;
138 Ext.Error.handle = function(err) {
139 expect(err.msg).toEqual('foo');
143 Ext.Error.raise({msg: 'foo'});
146 expect('Error should not have been caught').toBe(true);
148 expect(Ext.global.console.warn).not.toHaveBeenCalled();
149 Ext.Error.handle = origHandle;
153 describe("passing an object with custom metadata", function() {
155 it("should throw an error with matching metadata", function() {
165 expect(err.msg).toEqual('Custom error');
166 expect(err.data).not.toBe(null);
167 expect(err.data.foo).toEqual('bar');
171 it("should log the complete metadata to the console", function() {
172 spyOn(Ext.global.console, 'dir').andCallFake(function(err){
173 expect(err.msg).toEqual('Custom error');
174 expect(err.data).not.toBe(null);
175 expect(err.data.foo).toEqual('bar');
189 describe("originating from within a class defined by Ext", function() {
191 Ext.define('CustomClass', {
192 doSomething: function(o){
200 var customObj = Ext.create('CustomClass');
202 it("should throw an error containing the source class and method", function() {
204 customObj.doSomething({
209 expect(err.msg).toEqual('Custom error');
210 expect(err.sourceClass).toEqual('CustomClass');
211 expect(err.sourceMethod).toEqual('doSomething');
215 it("should log the complete metadata to the console", function() {
216 spyOn(Ext.global.console, 'dir').andCallFake(function(err){
217 expect(err.msg).toEqual('Custom error');
218 expect(err.sourceClass).toEqual('CustomClass');
219 expect(err.sourceMethod).toEqual('doSomething');
220 expect(err.data).not.toBe(null);
221 expect(err.data.extraData).not.toBe(null);
222 expect(err.data.extraData).toEqual('extra');
223 expect(err.foo).toEqual('bar');
226 customObj.doSomething({