How to get Mocha to fail a test

后端 未结 4 558
遇见更好的自我
遇见更好的自我 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:22

    Use chai-as-promised, with native Mocha promise handlers.

    var chai = require('chai').use(require('chai-as-promised'));
    var should = chai.should(); // This will enable .should for promise assertions
    

    You no longer need done, simply return the promise.

    // Remove `done` from the line below
    it.only('validation should fail', function(/* done */) {
        var body = {
            title: "dffdasfsdfsdafddfsadsa",
            description: "Postman Description",
            beginDate: now.add(3, 'd').format(),
            endDate: now.add(4, 'd').format()
        }
    
        var rules = eventsValidation.eventCreationRules();
        var valMessages = eventsValidation.eventCreationMessages();
    
        // Return the promise
        return indicative
            .validateAll(rules, body, valMessages)
            .should.be.rejected; // The test will pass only if the promise is rejected
    
        // Remove done, we no longer need it
        // done();
    });
    

提交回复
热议问题