0

My Package.json code:

"dependencies": {
    "gulp-jest": "^2.0.0",
    "jest-cli": "^20.0.4",
    "supertest": "^1.2.0"
}      
"scripts": {
    "test": "gulp test"
}

my gulpfile test tasks are as

gulp.task('run-tests', (done) => {
  gulp.src(['__tests__'])
  .pipe(jest({ testMatch: ['**/*.test.js'] }))
  .on('error', (error) => {
    done(error);
  })
  .on('finish', () => {
    done();
  });
});

my testcase file is as

const request = require('supertest');
 test('POST: Should create a new plan', (done) => {
      request('https://localhost:3000')
        .post('/api/name')
        .set('authorization', `bearer ${accessToken}`)
        .set('content-type', 'application/json')
        .send({
          name: 'TestPlanCreated'
        })
        .end((err, res) => {
          if (err) {
            return done.fail(err);
          }
        expect(res.statusCode).toBe(299);
        done();
        });

On success it should give statusCode 200, i am making it fail by expecting other than 200 but test cases are not failing as well not passing.

Canta
  • 1,480
  • 1
  • 13
  • 26
Nikita S
  • 139
  • 2
  • 11

1 Answers1

0

I changed my task as:

gulp.task('run-tests', (done) => {
  const options = {
    projects: [__dirname],
    silent: true,
    testMatch: ['**/?(*.)(test).js?(x)'],
    runInBand: true,
  };
  jest.runCLI(options, [__dirname])
  .then((result) => {
    if (result.numFailedTestSuites || result.numFailedTests) {
      return done(result);
    }
    return done();
  })
  .catch(error => done(error));
});

And updated packges to

"gulp-nsp": "^2.4.2",
"gulp-sequence": "^0.4.6",
"jest-cli": "^21.1.0",

Now test cases started to fail/Pass.

Vincent D'amour
  • 3,746
  • 1
  • 27
  • 39
Nikita S
  • 139
  • 2
  • 11