UNPKG

951 BJavaScriptView Raw
1const assert = require('assert');
2const co = require('../cockrel');
3
4
5
6describe("Plugin: error", function() {
7
8
9 it("handles error chains that end with an error", function(done) {
10
11 co
12 .do((data) => { throw new Error('woop'); })
13 .error(co.do((err) => { return 1; }).end())
14 .do(antiCheck)
15 .begin(123)
16 .catch(check);
17
18 function antiCheck(data) {
19 throw new Error('Should never have reached here!');
20 }
21
22 function check(error) {
23 assert.equal(error, 1);
24 done();
25 }
26
27 });
28
29 it("handles error chains that end with a success", function(done) {
30
31 co
32 .do((data) => { throw new Error('woop'); })
33 .error(co.do((err) => { return 1; }))
34 .do(check)
35 .begin(123)
36 .catch(antiCheck);
37
38 function antiCheck(data) {
39 throw new Error('Should never have reached here!');
40 }
41
42 function check(data) {
43 assert.equal(data, 1);
44 done();
45 }
46
47 });
48
49
50
51});