0.0.0 • Published 8 years ago
co-throws v0.0.0
co-throws
Assert that a given promise or generator throws an error asynchronously. I honestly don't know if there are better solutions or ways of testing if an asynchronous operation throws an error, so thats why I made this litte tool.
Before
const assert = require('assert')
describe('Something', () => {
it('throws an exception', function * () {
const user = new User({ email: '', password: 'Example123' })
try {
yield user.save()
throw Error()
} catch (err) {
assert.equal(err.message, 'email can\'t be blank')
}
user.set('email', 'user@example.com')
yield user.save()
})
})
After
const throws = require('co-throws')
describe('Something', () => {
it('throws an exception', function * () {
const user = new User({ email: '', password: 'Example123' })
yield throws(() => user.save(), /email can't be blank/)
user.set('email', 'user@example.com')
yield user.save()
})
})