Skip to content

Instantly share code, notes, and snippets.

@pgericson
Last active November 1, 2017 00:40
Show Gist options
  • Save pgericson/e7020f419b13aa0dcc5c0a3be35f7c6c to your computer and use it in GitHub Desktop.
Save pgericson/e7020f419b13aa0dcc5c0a3be35f7c6c to your computer and use it in GitHub Desktop.
Supertest+Jest - It jest don't work

Output that shows that mocha runs the tests correctly and jest don't

only one should pass

Jest (pass both)

$ jest
 PASS  ./test.js

 jest vs mocha in supertest
    ✓ should not work (40ms)
    ✓ should work (8ms)

Test Summary
 › Ran all tests.
 › 2 tests passed (2 total in 1 test suite, run time 2.192s)

Mocha (pass one)

$ mocha


  jest vs mocha in supertest
    1) should not work
    ✓ should work


  1 passing (72ms)
  1 failing

  1) jest vs mocha in supertest should not work:
     Error: expected 999 "undefined", got 200 "OK"
      at Test.assert (node_modules/supertest/lib/test.js:205:15)
      at Server.assert (node_modules/supertest/lib/test.js:132:12)
      at emitCloseNT (net.js:1549:8)
      at _combinedTickCallback (internal/process/next_tick.js:71:11)
      at process._tickCallback (internal/process/next_tick.js:98:9)
{
"name": "jest-supertest-dont-work",
"version": "1.0.0",
"description": "it jest don't work",
"main": "test.js",
"scripts": {
"test": "jest"
},
"author": "noone <blabla@blabla.com>",
"dependencies": {
"express": "4.11.2",
"jest-cli": "15.1.1"
},
"devDependencies": {
"jest-cli": "15.1.1",
"mocha": "3.0.2",
"supertest": "0.15.0"
},
"jest": {
"testRegex": "test\\.js"
}
}
'use strict';
var request = require('supertest');
var express = require('express');
var app = express();
var users = ['Buddy'];
app.get('/users', function (req, res) {
res.json(users);
});
describe('jest vs mocha in supertest', function() {
it('should not work', function(done) {
request(app)
.get('/users')
.expect(999, done)
});
it('should work', function(done) {
request(app)
.get('/users')
.expect(200, done)
});
});
@HaveF
Copy link

HaveF commented Dec 10, 2016

So this is still not works, but why? What a obvious bug is!

@HaveF
Copy link

HaveF commented Dec 10, 2016

describe('jest vs mocha in supertest', function() {
  it('should not work', function() {
    return request(app)
      .get('/users')
      .expect(999)
  });

  it('should work', function() {
    return request(app)
      .get('/users')
      .expect(200)
  });
});

do this would work
Tutorial – Async · Jest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment