Skip to content

Commit 4acd17e

Browse files
committed
Check that tests report errors like they should
1 parent 50a13b5 commit 4acd17e

File tree

3 files changed

+59
-33
lines changed

3 files changed

+59
-33
lines changed

lib/vows/context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ this.Context = function (vow, ctx, env) {
2828
if (typeof(e) === 'boolean' && args.length === 0) {
2929
that.emitter.emit.call(that.emitter, 'success', e);
3030
} else {
31-
if (e) { that.emitter.emit.apply(that.emitter, ['error', e].concat(args)) }
31+
if (e) { console.log('hi'); that.emitter.emit.apply(that.emitter, ['error', e].concat(args)) }
3232
else { that.emitter.emit.apply(that.emitter, ['success'].concat(args)) }
3333
}
3434
};

test/vows-error-test.js

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ var path = require('path'),
22
events = require('events'),
33
assert = require('assert'),
44
fs = require('fs'),
5-
vows = require('../lib/vows');
5+
vows = require('../lib/vows'),
6+
silent = require('../lib/vows/reporters/silent');
67

78
function doSomethingAsync(callback) {
89
var err = null;
@@ -48,4 +49,59 @@ vows.describe('vows/error').addBatch({
4849
assert.equal(testValue, 'a');
4950
}
5051
}
51-
}).export(module)
52+
}).export(module)
53+
54+
vows.describe('Error Handling').addBatch({
55+
"A topic with a function that errors": {
56+
topic: function() {
57+
throw("Something wrong here");
58+
},
59+
"should return an error to a vow with two parameters": function(e, data) {
60+
assert.equal(e, "Something wrong here");
61+
}
62+
},
63+
"A topic with a built-in error": {
64+
topic: function() {
65+
bad.bad;
66+
},
67+
"should return an error to a vow with two parameters": function(e, data) {
68+
assert(e instanceof Error, "Return value " + e + " wasn't an Error.");
69+
}
70+
},
71+
"The previous two topics run in their own suite," : {
72+
"connected to two vows expecting one argument each" : {
73+
topic: function(){
74+
vows.describe().addBatch({
75+
"A topic with a function that errors": {
76+
topic: function() {
77+
throw("Something wrong here");
78+
},
79+
"should record the error in the test results" : function(data) {
80+
assert.ok(!data);
81+
}
82+
//» An unexpected error was caught: "Something wrong here"
83+
},
84+
"A topic with a built-in error": {
85+
topic: function() {
86+
bad.bad;
87+
},
88+
"should record the error in the test results" : function(data) {
89+
assert.ok(!data);
90+
}
91+
//» An unexpected error was caught: ReferenceError: bad is not defined
92+
}
93+
}).run({reporter : silent}, this.callback);
94+
},
95+
"should have an errored count of two" : function(results, unused) {
96+
assert.equal(results.errored, 2);
97+
},
98+
"should have a total count of two" : function(results, unused) {
99+
assert.equal(results.total, 2);
100+
},
101+
"should have an honored count of zero" : function(results, unused){
102+
assert.equal(results.honored, 0);
103+
}
104+
}
105+
}
106+
}).export(module);
107+

test/vows-test.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -171,36 +171,6 @@ vows.describe("Vows").addBatch({
171171
}
172172
}
173173
},
174-
"A topic with a function that errors": {
175-
topic: function() {
176-
throw("Something wrong here");
177-
},
178-
"should return an error to a vow with two parameters": function(e, data) {
179-
assert.equal(e, "Something wrong here");
180-
}
181-
// TODO: make a test that runs a vows suite and check the error count
182-
//,
183-
// "and record the error in the test results otherwise" : function(data) {
184-
// assert.ok(!data);
185-
// }
186-
//✗ and record the error in the test results otherwise
187-
// » An unexpected error was caught: "Something wrong here"
188-
},
189-
"A topic with a built-in error": {
190-
topic: function() {
191-
bad.bad;
192-
},
193-
"should return an error to a vow with two parameters": function(e, data) {
194-
assert(e instanceof Error, "Return value " + e + " wasn't an Error.");
195-
}
196-
// TODO: make a test that runs a vows suite and check the error count
197-
//,
198-
// "and record the error in the test results otherwise" : function(data) {
199-
// assert.ok(!data);
200-
// }
201-
//✗ and record the error in the test results otherwise
202-
// » An unexpected error was caught: ReferenceError: bad is not defined
203-
},
204174
"A topic emitting an error": {
205175
topic: function () {
206176
var promise = new(events.EventEmitter);

0 commit comments

Comments
 (0)