Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#870 5 bình luận 12 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, node.js
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu bằng cách đọc commit 15a1bc449ab529d540eb9c2be4e093f9f5b0278d và xác định decode được định nghĩa như thế nào trong node-jsonwebtoken. Tái hiện việc gán lại trực tiếp được trình bày trong issue, sau đó xác minh rằng có thể thay đổi decode mà không gặp TypeError và bổ sung coverage cho hành vi đó.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
JavaScript
Star
18.2k
Fork
1.3k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của auth0/node-jsonwebtoken

Tất cả issue của auth0/node-jsonwebtoken

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.