busterjs / buster

Abandoned - A powerful suite of automated test tools for JavaScript.
http://docs.busterjs.org
Other
448 stars 37 forks source link

Referee: assert.exception does not check exception type #387

Closed olance closed 10 years ago

olance commented 10 years ago

For assert.exception(callback[, type, message]), the documentation states the following:

If the optional type is provided, the assertion fails if the callback either does not throw an exception, or if the exception is not of the given type (determined by its name property)

However:

expect(-> throw new Error('blah')).toThrow('TypeError')

will pass.

dwittner commented 10 years ago

Seems the signature of the function has changed from assert.exception(callback[, type, message]) to assert.exception(callback[, matcher, message]). So it is more flexible now. You can pass an object with which the error object must match or a function which is responsible to verify the error object. But it seems it isn't intended to support the feature of just passing the type of the error as string further. Unfortunately the documentation isn't changed yet.

@cjohansen, I think we should still support the feature of just passing the error type as string. I am not sure, but it seems the code block if (typeof matcher === "string") { ... } is currently dead code. I think it was originally intended to provide the ability to pass a message without a matcher. If this is the case, we have to decide if we prefer the type matcher or the ability to pass a message without a matcher. I am for the type matcher.