source: imaps-frontend/node_modules/pretty-error/test/PrettyError.coffee

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[79a0317]1chai = require 'chai'
2PrettyError = require '../src/PrettyError'
3defaultStyle = require '../src/defaultStyle'
4
5chai.should()
6
7isFormatted = (exc) ->
8 exc.stack.indexOf(' \u001b[0m\u001b[97m\u001b[41m') is 0
9
10error = (what) ->
11 if typeof what is 'string'
12 return error -> throw Error what
13
14 else if what instanceof Function
15 try
16 do what
17 catch e
18 return e
19
20 throw Error "bad argument for error"
21
22describe "PrettyError", ->
23 describe "constructor()", ->
24 it "should work", ->
25 new PrettyError
26
27 describe "getObject", ->
28 it "should return a string", ->
29 p = new PrettyError
30 p.getObject(error "hello").should.be.an 'object'
31
32 describe "style", ->
33 it "should, by default, return the contents in `default-style`", ->
34 p = new PrettyError
35 p.style.should.eql defaultStyle()
36
37 it "should return different contents after appending some styles", ->
38 p = new PrettyError
39 p.appendStyle 'some selector': 'display': 'block'
40 p.style.should.not.eql defaultStyle()
41
42 describe "render()", ->
43 it "should work", ->
44 p = new PrettyError
45 p.skipNodeFiles()
46 p.appendStyle 'pretty-error': marginLeft: 4
47
48 e = error -> "a".should.equal "b"
49 console.log p.render e, no
50
51 e2 = error -> Array.split(Object)
52 console.log p.render e2, no
53
54 e3 = "Plain error message"
55 console.log p.render e3, no
56
57 e4 =
58 message: "Custom error message"
59 kind: "Custom Error"
60
61 console.log p.render e4, no
62
63 e5 =
64 message: "Error with custom stack"
65 stack: ['line one', 'line two']
66 wrapper: 'UnhandledRejection'
67
68 console.log p.render e5, no
69
70 e6 = error -> PrettyError.someNonExistingFuncion()
71 console.log p.render e6, no
72
73 it.skip "should render without colors if pe._useColors is false", ->
74 p = new PrettyError
75 p.withoutColors()
76 p.skipNodeFiles()
77 p.appendStyle 'pretty-error': marginLeft: 4
78
79 e = error -> "a".should.equal "b"
80 console.log p.render e, no
81
82 describe "start()", ->
83 prepareStackTrace = null
84
85 beforeEach ->
86 {prepareStackTrace} = Error
87 Error.prepareStackTrace = null
88
89 afterEach ->
90 Error.prepareStackTrace = prepareStackTrace
91
92 it "throws unformatted error when not started", ->
93 try
94 throw new Error "foo bar"
95 catch exc
96
97 isFormatted(exc).should.be.eql false
98
99 it "throws formatted the error", ->
100 PrettyError.start()
101
102 try
103 throw new Error "foo bar"
104 catch exc
105
106 isFormatted(exc).should.be.eql true
107 exc.stack.split(/\n/g).length.should.be.above 2
108
109 PrettyError.stop()
Note: See TracBrowser for help on using the repository browser.