Skip to content

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

Open
@carrolp

Description

@carrolp

Description

Changes to how decode is defined in 9.0.0 (15a1bc4) 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions