Skip to content

Commit

Permalink
test: fix broken
Browse files Browse the repository at this point in the history
  • Loading branch information
chunkai1312 committed Jan 1, 2020
1 parent 19be2a1 commit f8195f9
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions test/express-error-slack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ const sinon = require('sinon')
const errorToSlack = require('../lib')

describe('Express Error Slack', () => {
const spy = sinon.spy(Slack.prototype, 'webhook')
const sandbox = sinon.createSandbox()
let spy

beforeEach(() => {
spy.reset()
spy = sandbox.spy(Slack.prototype, 'webhook')
})

afterEach(() => {
sandbox.restore()
})

it('should throw error if options not a object', () => {
Expand Down Expand Up @@ -59,6 +64,22 @@ describe('Express Error Slack', () => {
})
})

it('should send error to slack if error exists', (done) => {
const app = express()
app.use((req, res, next) => next(1))
app.use(errorToSlack({ webhookUri: 'https://hooks.slack.com/services/TOKEN' }))

request(app)
.get('/')
.expect(500)
.end((err, res) => {
expect(err).to.not.exist
expect(spy.calledOnce).to.be.true
expect(spy.args[0][0].attachments[0]).to.have.property('color', 'danger')
done()
})
})

it('should skip to send error to slack if options.skip returns true', (done) => {
const app = express()
app.use((req, res, next) => next(createError(404)))
Expand Down

0 comments on commit f8195f9

Please sign in to comment.