How to get Mocha to fail a test

后端 未结 4 547
遇见更好的自我
遇见更好的自我 2021-02-02 07:15

I have the following test:

it.only(\'validation should fail\', function(done) {
    var body = {
        title: \"dffdasfsdfsdafddfsadsa\",
        description:          


        
4条回答
  •  借酒劲吻你
    2021-02-02 08:07

    In the ES2017 async/await world chai-as-promised is not needed as much. Although simple rejections are one place chai-as-promised remains a little neater to use.

    A catch is required if you want to test the error in more detail.

    it.only('validation should fail', async function(){
        let body = { ... }
        let rules = eventsValidation.eventCreationRules()
        let valMessages = eventsValidation.eventCreationMessages()
    
        try {
            await indicative.validateAll(rules, body, valMessages)
        } catch (error) {
            expect(error).to.be.instanceOf(Error)
            expect(error.message).to.match(/Oh no!/)
            return
        }
        expect.fail(null, null, 'validateAll did not reject with an error')
        // or throw new Error('validateAll did not reject with an error')
    })
    

    async/await requires Node.js 7.6+ or a compiler like Babel

提交回复
热议问题