describe('API testing: meeting', function () {
it('Testing meeting update view count call without error', function (done) {
request(app).post('/meeting/updateViewCount').send({ videoId: 17 }).set('Accept', 'application/json').expect(200).end(function (err, res) {
should.not.exist(err);
should.exist(res.body);
expect(res.body.status).to.equal('Success');
done();
});
});-- In above test case am passing invalid videoId as 17 no record exists with this id and it will fail and mocha throws below error and exit.throw err;
^
AssertionError: expected 'Error' to equal 'Success'
But I want it to continue further executing below test and also other in many files and show the result of passed and failed with proper execution. it('Testing meeting update view count call with error', function (done) {
request(app).post('/meeting/updateViewCount').send({ videoId: 's' }).set('Accept', 'application/json').expect(200).end(function (err, res) {
expect(res.body.status).to.equal('Error');
done();
});
});
});Kindly give your suggestions, I am new to mocha tests, earlier i worked on java and grails testing frameworks where i never faced any such issues.ThanksSandeep
Hi Vlad, Thank you so much for looking into the issue. Please find below information about the plugins i am using for my tests.
I have an init file, with below nodejs plugins i am initialising using --require ./test/init.js in mocha.opts which will load below plugins into global object and it will be available for all the test files
'use strict';
require('dotenv').load();
global.chai = require('chai');
global.chai.should();
global.expect = global.chai.expect;
global.assert = global.chai.assert;
global.should = global.chai.should();
global.request = require('supertest');
var _ = require('underscore');
global._ = _
var express = require('express');
var bodyParser = require('body-parser')
var app = express();
var routes = require(process.env.ROOTDIR + 'routes');
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: false}));
app.use('/',routes)
so app, assert, expect and should are the global variables which i am loading with above lines.
Appreciate your kind support.
Thanks
Sandeep
at Test.assert (/Users/svedavya/Documents/cisco_codebase/back2customer/package/repo/node_modules/supertest/lib/test.js:179:6)
at Server.assert (/Users/svedavya/Documents/cisco_codebase/back2customer/package/repo/node_modules/supertest/lib/test.js:131:12)