Questions tagged [supertest]

SuperTest is a module that provides high-level abstraction for testing HTTP in node.js, using low-level API provided by super-agent.

SuperTest is a module that provides high-level abstraction for testing HTTP in node.js, using low-level API provided by super-agent.

922 questions
6
votes
3 answers

How to authenticate Supertest requests with Passport /Facebook strategy/?

I'm using Passport.js for authentication (Facebook strategy) and testing with Mocha and Supertest. How can I create a session and make authenticated requests with Supertest for Facebook strategy? Here is the example test for when user not logged…
Zeck
  • 6,433
  • 21
  • 71
  • 111
5
votes
2 answers

Set an authentication token in a request header when using supertest with jest and express

I'm trying to test the routes in my express app that are protected by a jwt middleware. I've tried simulating a request to get the jwt token in a beforeAll call: let token = ""; beforeAll((done) => { supertest(app) …
JimmyTheCode
  • 3,783
  • 7
  • 29
  • 71
5
votes
1 answer

How to print the request logs (like request url,request body, request queryParam) on supertest failure?

I want to print or console log below details on failure for Supertest expect failure for the below request on success no need to print any thing on success const result = await request(dummy_url).get("repos/Microsoft/TypeScript/pulls") …
Bharathan Kumaran
  • 981
  • 10
  • 22
5
votes
0 answers

Mochawesome includes javascript code instead of typescript

I've written a few api tests in Typescript with mocha + supertest. I run my tests with the 'ts' files only, the following way: "api:test": "cross-env TS_NODE_PROJECT='tsconfig.api.json' mocha -r ts-node/register 'test/api/**/*.ts' --reporter…
wfmn17
  • 134
  • 1
  • 3
  • 20
5
votes
2 answers

NodeJs testing Error: Timeout of 2000ms exceeded

I am testing multiple responses but always end up with the same error message: Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/this/file/path.js) let…
5
votes
3 answers

How can I test express server with supertest in next.js?

I have built my portfolio webpage with next.js now I need to test it. to test the express server I use supertest. But the problem is I need to refactor express to use it. Because supertest need to access to app() before listening. I started the way…
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
5
votes
1 answer

How does one properly to unit test Joi Schemas validation?

I created a Joi validation schema that gets called in my routes. However when I run a code coverage that file is NOT being covered. So, I am trying to write a test for it. Validator.js const Joi = require('joi'); module.exports = { …
Archezo
  • 53
  • 1
  • 6
5
votes
1 answer

Testing express NodeJS endpoints using supertest

I'm trying to set up a test environment to test my typescript express nodejs endpoints but I can't seem to get it to work. I've installed: jest ts-jest jest-junit supertest @types/supertest @types/jest this is how spec file looks: import * as…
Mout Pessemier
  • 1,665
  • 3
  • 19
  • 33
5
votes
2 answers

Supertest/Jest check if header exists

Is there a way to check if a certain header exists in the response using supertest and jest? e.g expect(res.headers).toContain('token')
georgesamper
  • 4,989
  • 5
  • 40
  • 59
5
votes
2 answers

Using supertest in TypeScript - Getting problem "cannot invoke expression whose type lacks a call signature"

I am trying to use supertest with TypeScript after initially using with JavaScript. However I am now receiving red squiggles under my code stating: cannot invoke expression whose type lacks a call signature. Type 'typeof supertest' has no…
physicsboy
  • 5,656
  • 17
  • 70
  • 119
5
votes
1 answer

Unable to send authenticated request in tests using Jest, Supertest, Passport, Koa2 Again

I've been trying to use internetross's March 2018 answer to no avail. I too am using Jest, Supertest, and in my case Koa and Passport. Using REST client in Visual Studio, no problem. The session gets pass through, Passport authenticates, and I get…
Crivens
  • 333
  • 3
  • 13
5
votes
2 answers

Passing request body to post using super-test

I'm testing an express server using super-test and I need to test a post call. I assume the post should be successful and return a status of 200 but it is returning 401. I've been told by someone that I need to pass a request body with the post…
jwolsborn
  • 576
  • 1
  • 6
  • 26
5
votes
1 answer

How to encapsulate mocha `expect()` code?

I'm trying to test for the presence of some api response properties that I want to require across all tests (a status and data property). Here's a generic test that asserts the desired properties in a supertest expect() method: it('should create…
doub1ejack
  • 10,627
  • 20
  • 66
  • 125
5
votes
1 answer

'mocha' is not recognized as an internal or external command - mocha not getting automatically installed with supertest

I need to unit-test my rest api written in NodeJS. For this, I need to use supertest npm package. I was following this tutorial article for implementing the unit test functionality. Now, in this article it is mentioned that mocha is already included…
Mohit Bhardwaj
  • 9,650
  • 3
  • 37
  • 64
5
votes
1 answer

supertest e2e with nestjs: request is not a function

I try to introduce e2e tests for my simple NestJS backend services. I am providing a custom userService and a custom UserRepository mocked with sinon. This is my user.e2e-spec.ts file: import * as request from 'supertest'; import * as sinon from…