nestjs / jwt

JWT utilities module based on the jsonwebtoken package 🔓

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tests are written with numerous gross mistakes

KostyaTretyak opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Tests are written with numerous gross mistakes. For example:

  1. In this code and all async tests with .resolves. / .rejects. syntax:

it('signing (async) should use SIGN option function', async () => {
expect(jwtService.signAsync('random')).resolves.toBe(
config.secretOrKeyProvider(JwtSecretRequestType.SIGN)
);
});

You need to put await before expect. See docs for Testing Asynchronous Code.

  1. After that, the tests start to crash with a timeout. This is because the wrong configuration of jest spy. As far as I understand, jest spy is not used at all.

  2. If you remove jest spy, the tests begin to fail due to incorrect expectations. For example sign() returns token, but here expected secret:

it('signing should use secret key', async () => {
expect(await jwtService.sign('random')).toBe(config.secret);
});

  1. And so on...

Minimum reproduction code

No response

Steps to reproduce

No response

Expected behavior

Tests must be written accurately and correctly.

Package version

8.0.0

NestJS version

No response

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Tests were added via external contribution as part of this commit 9bae007. Feel free to create a follow-up PR to improve them.