question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rfc: supertest support

See original GitHub issue

This could be technically out of scope for eslint-plugin-jest, but I’ve been using supertest, and some of our rules don’t really work nicely w/ it:

test('GET /live', async () => {
  await request(app)
    .get('/live')
    .expect('Content-Type', /json/)
    .expect(HttpStatus.OK)
    .expect('');
});

jest/expect-expect can’t handle .expect as a method being called on something, so I have to add request, which means I could forget a .expect and have problems.

It’d also be great to support warning that request needs to be either awaited or returned, as it’s a promise. I think this could be covered by one of our existing rules.

Using return also annoys jest/no-test-return-statement.

I don’t think we could catch every possible way of using supertest, and I’ve only just started using it myself, but I’m interested in gathering some initial comments & thoughts on if there’s any low-hanging fruit we could aim for that’d improve things w/o much work.

The main one for me is improving expect-expect to support .expect() - logic-wise easy, but the configuration would be interesting.

Theres also an argument that could be made about jest/lowercase-name supporting ignoring GET /live.

Right now, I’m feeling like this might be worth it’s own plugin at some point, but as far as I know theres no nice way of composing rules - instead you’d just have to clone rules like jest/lowercase-name into eslint-plugin-supertest, a la @typescript-eslint does w/ the eslint rules.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
SimenBcommented, Sep 30, 2019

I don’t think this belongs this plugin. Seems more natural in a eslint-plugin-supertest or whatever.

We use supertest at work, but we never use the assertions from it. Mostly because they don’t give proper stack traces.

test('GET /live', async () => {
  const { headers, status, body } = await request(app).get('/live');

  expect(headers.contentType).toMatch(/json/);
  expect(status).toBe(200);
  expect(body).toBe('');
});

(written free hand, haven’t looked up the actual APIs)

1reaction
G-Rathcommented, Nov 9, 2019

Thanks for that @erunion - would you mind opening that as a separate issue for tracking?

At least you should be able to put something like sinon.assert.calledOnce into assertFunctionNames and have it work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[RFC] kunit: Support for Parameterized Testing - Google Groups
This patch has a basic implementation for adding support for parameterized testing in KUnit. It is not complete.
Read more >
RFC 7240's "Prefer: wait" instead of "Timeout" header
I emailed the IETF HTTP group about my timeout header idea, and a few people said that RFC 7240's "wait" preference" does what...
Read more >
RFC - kernel selftest result documentation (KTAP)
Tim Bird has just sent out an RFC for a "KTAP" specification, which > we'll hope to support in KUnit: Ah-ha! Thanks for...
Read more >
axios vs pactum vs request vs superagent vs supertest vs ...
Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default. const request...
Read more >
10 Best Practices for Writing Node.js REST APIs
One of the modules that can help you with black-box testing Node.js REST APIs is supertest. A simple test case which checks if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found