|
| 1 | +import { |
| 2 | + AsyncTestCompleter, |
| 3 | + beforeEach, |
| 4 | + ddescribe, |
| 5 | + describe, |
| 6 | + expect, |
| 7 | + iit, |
| 8 | + inject, |
| 9 | + it, |
| 10 | + xdescribe, |
| 11 | + xit, |
| 12 | + IS_DARTIUM, |
| 13 | + Log |
| 14 | +} from 'angular2/test_lib'; |
| 15 | +import {BaseException} from 'angular2/src/facade/lang'; |
| 16 | +import {ExceptionHandler} from 'angular2/src/core/exception_handler'; |
| 17 | + |
| 18 | +class _CustomException { |
| 19 | + context = "some context"; |
| 20 | +} |
| 21 | + |
| 22 | +export function main() { |
| 23 | + describe('ExceptionHandler', () => { |
| 24 | + var log, handler; |
| 25 | + |
| 26 | + beforeEach(() => { |
| 27 | + log = new Log(); |
| 28 | + handler = new ExceptionHandler(); |
| 29 | + handler.logError = (e) => log.add(e); |
| 30 | + }); |
| 31 | + |
| 32 | + it("should output exception", () => { |
| 33 | + try { |
| 34 | + handler.call(new BaseException("message!")); |
| 35 | + } catch (e) { |
| 36 | + } |
| 37 | + expect(log.result()).toContain("message!"); |
| 38 | + }); |
| 39 | + |
| 40 | + it("should output stackTrace", () => { |
| 41 | + try { |
| 42 | + handler.call(new BaseException("message!"), "stack!"); |
| 43 | + } catch (e) { |
| 44 | + } |
| 45 | + expect(log.result()).toContain("stack!"); |
| 46 | + }); |
| 47 | + |
| 48 | + it("should join a long stackTrace", () => { |
| 49 | + try { |
| 50 | + handler.call(new BaseException("message!"), ["stack1", "stack2"]); |
| 51 | + } catch (e) { |
| 52 | + } |
| 53 | + expect(log.result()).toContain("stack1"); |
| 54 | + expect(log.result()).toContain("stack2"); |
| 55 | + }); |
| 56 | + |
| 57 | + it("should output reason when present", () => { |
| 58 | + try { |
| 59 | + handler.call(new BaseException("message!"), null, "reason!"); |
| 60 | + } catch (e) { |
| 61 | + } |
| 62 | + expect(log.result()).toContain("reason!"); |
| 63 | + }); |
| 64 | + |
| 65 | + it("should print context", () => { |
| 66 | + try { |
| 67 | + handler.call(new BaseException("message!", null, null, "context!")); |
| 68 | + } catch (e) { |
| 69 | + } |
| 70 | + expect(log.result()).toContain("context!"); |
| 71 | + }); |
| 72 | + |
| 73 | + it("should print nested context", () => { |
| 74 | + try { |
| 75 | + var original = new BaseException("message!", null, null, "context!"); |
| 76 | + handler.call(new BaseException("message", original)); |
| 77 | + } catch (e) { |
| 78 | + } |
| 79 | + expect(log.result()).toContain("context!"); |
| 80 | + }); |
| 81 | + |
| 82 | + it("should not print context when the passed-in exception is not a BaseException", () => { |
| 83 | + try { |
| 84 | + handler.call(new _CustomException()); |
| 85 | + } catch (e) { |
| 86 | + } |
| 87 | + expect(log.result()).not.toContain("context"); |
| 88 | + }); |
| 89 | + }); |
| 90 | +} |
0 commit comments