1 describe("Ext.Error", function() {
4 beforeEach(function() {
7 // mock the console to avoid logging to the real console during the tests
23 afterEach(function() {
27 describe("raising an error via Ext.Error.raise", function() {
29 describe("passing a string", function() {
31 it("should throw an error with a msg property", function() {
33 Ext.Error.raise('foo');
36 expect(err.msg).toEqual('foo');
40 it("should log an error to the console", function() {
41 spyOn(Ext.global.console, 'error');
43 Ext.Error.raise('foo');
46 expect(Ext.global.console.error).toHaveBeenCalledWith('foo');
49 it("should log the error object to the console", function() {
50 spyOn(Ext.global.console, 'dir').andCallFake(function(err){
51 expect(err.msg).toEqual('foo');
54 Ext.Error.raise('foo');
59 it("should do nothing when Ext.Error.ignore = true", function() {
60 spyOn(Ext.global.console, 'warn');
62 Ext.Error.ignore = true;
64 Ext.Error.raise('foo');
67 expect('Error should not have been caught').toBe(true);
69 expect(Ext.global.console.warn).not.toHaveBeenCalled();
70 Ext.Error.ignore = false;
73 it("should not throw an error if handled by Ext.Error.handle", function() {
74 spyOn(Ext.global.console, 'warn');
76 var origHandle = Ext.Error.handle;
77 Ext.Error.handle = function(err) {
78 expect(err.msg).toEqual('foo');
82 Ext.Error.raise('foo');
85 expect('Error should not have been caught').toBe(true);
87 expect(Ext.global.console.warn).not.toHaveBeenCalled();
88 Ext.Error.handle = origHandle;
92 describe("passing an object with a msg property", function() {
94 it("should throw an error with a msg property", function() {
96 Ext.Error.raise({msg: 'foo'});
99 expect(err.msg).toEqual('foo');
103 it("should log a warning to the console", function() {
104 spyOn(Ext.global.console, 'error');
106 Ext.Error.raise({msg: 'foo'});
109 expect(Ext.global.console.error).toHaveBeenCalledWith('foo');
112 it("should log the error object to the console", function() {
113 spyOn(Ext.global.console, 'dir').andCallFake(function(err){
114 expect(err.msg).toEqual('foo');
117 Ext.Error.raise({msg: 'foo'});
122 it("should do nothing when Ext.Error.ignore = true", function() {
123 spyOn(Ext.global.console, 'warn');
125 Ext.Error.ignore = true;
127 Ext.Error.raise({msg: 'foo'});
130 expect('Error should not have been caught').toBe(true);
132 expect(Ext.global.console.warn).not.toHaveBeenCalled();
133 Ext.Error.ignore = false;
136 it("should not throw an error if handled by Ext.Error.handle", function() {
137 spyOn(Ext.global.console, 'warn');
139 var origHandle = Ext.Error.handle;
140 Ext.Error.handle = function(err) {
141 expect(err.msg).toEqual('foo');
145 Ext.Error.raise({msg: 'foo'});
148 expect('Error should not have been caught').toBe(true);
150 expect(Ext.global.console.warn).not.toHaveBeenCalled();
151 Ext.Error.handle = origHandle;
155 describe("passing an object with custom metadata", function() {
157 it("should throw an error with matching metadata", function() {
167 expect(err.msg).toEqual('Custom error');
168 expect(err.data).not.toBe(null);
169 expect(err.data.foo).toEqual('bar');
173 it("should log the complete metadata to the console", function() {
174 spyOn(Ext.global.console, 'dir').andCallFake(function(err){
175 expect(err.msg).toEqual('Custom error');
176 expect(err.data).not.toBe(null);
177 expect(err.data.foo).toEqual('bar');
191 describe("originating from within a class defined by Ext", function() {
193 Ext.define('CustomClass', {
194 doSomething: function(o){
202 var customObj = Ext.create('CustomClass');
204 it("should throw an error containing the source class and method", function() {
206 customObj.doSomething({
211 expect(err.msg).toEqual('Custom error');
212 expect(err.sourceClass).toEqual('CustomClass');
213 expect(err.sourceMethod).toEqual('doSomething');
217 it("should log the complete metadata to the console", function() {
218 spyOn(Ext.global.console, 'dir').andCallFake(function(err){
219 expect(err.msg).toEqual('Custom error');
220 expect(err.sourceClass).toEqual('CustomClass');
221 expect(err.sourceMethod).toEqual('doSomething');
222 expect(err.data).not.toBe(null);
223 expect(err.data.extraData).not.toBe(null);
224 expect(err.data.extraData).toEqual('extra');
225 expect(err.foo).toEqual('bar');
228 customObj.doSomething({