Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

decode does not allow stubbing for unit test with libraries such as sinon

Open
#870 5 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
javascript, node.js
Domain
api, backend

Research direction

Start by reading commit 15a1bc449ab529d540eb9c2be4e093f9f5b0278d and locating how decode is defined in node-jsonwebtoken. Reproduce the direct reassignment shown in the issue, then verify that decode can be altered without the TypeError and add coverage for that behavior.

Written by the indexing model from the issue text.

Description

Description

Changes to how decode is defined in 9.0.0 (https://github.com/auth0/node-jsonwebtoken/commit/15a1bc449ab529d540eb9c2be4e093f9f5b0278d) prevent it from being altered for unit tests by tools such as sinon, or even direct alteration such as

jwt.decode = function() { return( 'teststring' ); };

As a result errors such as TypeError: Cannot redefine property: decode are thrown in these scenarios.

Other JWT libraries such as jose have added configurable: true to allow this scenario to succeed, which should probably be done here too:

Reproduction

Test code such as

jwt.decode = function() { return( 'teststring' ); };

results in

TypeError: Cannot redefine property
Environment
  • Version of this library used: 9.0.0
  • Version of the platform or framework used, if applicable: n/a
  • Other relevant versions (language, server software, OS, browser): n/a
  • Other modules/plugins/libraries that might be involved: n/a
Dominant language
JavaScript
Stars
18.2k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from auth0/node-jsonwebtoken

All issues in auth0/node-jsonwebtoken

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.