Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(695)

Side by Side Diff: appengine/config_service/ui/bower_components/sinon-chai/test/throwing.coffee

Issue 2923973003: Added base template for config ui. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 "use strict"
2
3 sinon = require("sinon")
4
5 describe "Throwing", ->
6 describe "thrown()", ->
7 it "should throw an assertion error if the spy does not throw at all", - >
8 spy = sinon.spy.create(->)
9
10 spy()
11
12 expect(-> spy.should.have.thrown()).to.throw(AssertionError)
13 expect(-> spy.getCall(0).should.have.thrown()).to.throw(AssertionErr or)
14
15 it "should not throw if the spy throws", ->
16 spy = sinon.spy.create(-> throw new Error())
17
18 swallow(spy)
19
20 expect(-> spy.should.have.thrown()).to.not.throw()
21 expect(-> spy.getCall(0).should.have.thrown()).to.not.throw()
22
23 it "should not throw if the spy throws once but not the next time", ->
24 spy = sinon.spy.create(-> throw new Error() unless spy.callCount > 1 )
25
26 swallow(spy)
27 swallow(spy)
28
29 expect(-> spy.should.have.thrown()).to.not.throw()
30 expect(-> spy.getCall(0).should.have.thrown()).to.not.throw()
31
32 describe "thrown(errorObject)", ->
33 error = null
34
35 beforeEach ->
36 error = new Error("boo!")
37
38 it "should throw an assertion error if the spy does not throw at all", - >
39 spy = sinon.spy.create(->)
40
41 spy()
42
43 expect(-> spy.should.have.thrown(error)).to.throw(AssertionError)
44 expect(-> spy.getCall(0).should.have.thrown(error)).to.throw(Asserti onError)
45
46 it "should throw an assertion error if the spy throws the wrong error", ->
47 spy = sinon.spy.create(-> new Error("eek!"))
48
49 swallow(spy)
50
51 expect(-> spy.should.have.thrown(error)).to.throw(AssertionError)
52 expect(-> spy.getCall(0).should.have.thrown(error)).to.throw(Asserti onError)
53
54 it "should not throw if the spy throws", ->
55 spy = sinon.spy.create(-> throw error)
56
57 swallow(spy)
58
59 expect(-> spy.should.have.thrown(error)).to.not.throw()
60 expect(-> spy.getCall(0).should.have.thrown(error)).to.not.throw()
61
62 it "should not throw if the spy throws once but not the next time", ->
63 spy = sinon.spy.create(-> throw error unless spy.callCount > 1)
64
65 swallow(spy)
66 swallow(spy)
67
68 expect(-> spy.should.have.thrown(error)).to.not.throw()
69 expect(-> spy.getCall(0).should.have.thrown(error)).to.not.throw()
70
71 describe "thrown(errorTypeString)", ->
72 error = null
73
74 beforeEach ->
75 error = new TypeError("boo!")
76
77 it "should throw an assertion error if the spy does not throw at all", - >
78 spy = sinon.spy.create(->)
79
80 spy()
81
82 expect(-> spy.should.have.thrown("TypeError")).to.throw(AssertionErr or)
83 expect(-> spy.getCall(0).should.have.thrown("TypeError")).to.throw(A ssertionError)
84
85 it "should throw an assertion error if the spy throws the wrong type of error", ->
86 spy = sinon.spy.create(-> throw new Error("boo!"))
87
88 swallow(spy)
89
90 expect(-> spy.should.have.thrown("TypeError")).to.throw(AssertionErr or)
91 expect(-> spy.getCall(0).should.have.thrown("TypeError")).to.throw(A ssertionError)
92
93 it "should not throw if the spy throws the correct type of error", ->
94 spy = sinon.spy.create(-> throw new TypeError("eek!"))
95
96 swallow(spy)
97
98 expect(-> spy.should.have.thrown("TypeError")).to.not.throw()
99 expect(-> spy.getCall(0).should.have.thrown("TypeError")).to.not.thr ow()
100
101 it "should not throw if the spy throws once but not the next time", ->
102 spy = sinon.spy.create(-> throw error unless spy.callCount > 1)
103
104 swallow(spy)
105 swallow(spy)
106
107 expect(-> spy.should.have.thrown("TypeError")).to.not.throw()
108 expect(-> spy.getCall(0).should.have.thrown("TypeError")).to.not.thr ow()
109
110 describe "always thrown", ->
111 error = null
112
113 beforeEach ->
114 error = new TypeError("boo!")
115
116 it "should throw an assertion error if the spy throws once but not the n ext time", ->
117 spy = sinon.spy.create(-> throw error unless spy.callCount > 1)
118
119 swallow(spy)
120 swallow(spy)
121
122 expect(-> spy.should.have.always.thrown()).to.throw(AssertionError)
123 expect(-> spy.should.always.have.thrown()).to.throw(AssertionError)
124 expect(-> spy.should.have.always.thrown(error)).to.throw(AssertionEr ror)
125 expect(-> spy.should.always.have.thrown(error)).to.throw(AssertionEr ror)
126 expect(-> spy.should.have.always.thrown("TypeError")).to.throw(Asser tionError)
127 expect(-> spy.should.always.have.thrown("TypeError")).to.throw(Asser tionError)
128
129 it "should throw an assertion error if the spy throws the wrong error th e second time", ->
130 spy = sinon.spy.create(-> if spy.callCount is 1 then throw error els e throw new Error())
131
132 swallow(spy)
133 swallow(spy)
134
135 expect(-> spy.should.have.always.thrown(error)).to.throw(AssertionEr ror)
136 expect(-> spy.should.always.have.thrown(error)).to.throw(AssertionEr ror)
137 expect(-> spy.should.have.always.thrown("TypeError")).to.throw(Asser tionError)
138 expect(-> spy.should.always.have.thrown("TypeError")).to.throw(Asser tionError)
139
140 it "should not throw if the spy always throws the right error", ->
141 spy = sinon.spy.create(-> throw error)
142
143 swallow(spy)
144 swallow(spy)
145
146 expect(-> spy.should.have.always.thrown(error)).to.not.throw()
147 expect(-> spy.should.always.have.thrown(error)).to.not.throw()
148 expect(-> spy.should.have.always.thrown("TypeError")).to.not.throw()
149 expect(-> spy.should.always.have.thrown("TypeError")).to.not.throw()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698