You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should have a way to pass errors from a topic to a single error handler per batch, or a single global handler.
The way we're handling errors in 1.x, you get a lot of duplication if you have multiple tests:
vows.describe("handle error once").addBatch({"When we read a file": {topic(){fs.readFile("/tmp/somefile.txt","utf8",this.callback)},"it is the right data type": (err,data)=>{assert.ifError(err)assert.isString(data)},"it is the right size": (err,data)=>{assert.ifError(err)assert.lengthOf(data,42)},"it has the right contents": (err,data)=>{assert.ifError(err)assert.match(data,/somecontents/)}}}).export(module)
It would be nice if, when you define an error handler for the batch, that would get called for any errors, and tests would only be run if there is no error.
vows.describe("handle error once").addBatch({"When we read a file": {topic(){fs.readFile("/tmp/somefile.txt","utf8",this.callback)},error(err){console.error(err)},"it is the right data type": (data)=>{assert.isString(data)},"it is the right size": (data)=>{assert.lengthOf(data,42)},"it has the right contents": (data)=>{assert.match(data,/somecontents/)}}}).export(module)
We could even have a mechanism for declaring a global error handler.
vows.options.errorHandler=(err)=>{console.error(err)}vows.describe("default error handler").addBatch({"When we read a file": {topic(){fs.readFile("/tmp/somefile.txt","utf8",this.callback)},"it is the right data type": (data)=>{assert.isString(data)},"it is the right size": (data)=>{assert.lengthOf(data,42)},"it has the right contents": (data)=>{assert.match(data,/somecontents/)}}}).export(module)
This would only handle errors from the topic:
If the topic function throws an Error
If this.callback is called with a first argument that's truthy
If the topic returns a Promise that reject()s
If any of the tests throw an error, that's treated as a test failure.
The text was updated successfully, but these errors were encountered:
We should have a way to pass errors from a topic to a single error handler per batch, or a single global handler.
The way we're handling errors in 1.x, you get a lot of duplication if you have multiple tests:
It would be nice if, when you define an error handler for the batch, that would get called for any errors, and tests would only be run if there is no error.
We could even have a mechanism for declaring a global error handler.
This would only handle errors from the topic:
this.callback
is called with a first argument that's truthyreject()
sIf any of the tests throw an error, that's treated as a test failure.
The text was updated successfully, but these errors were encountered: