Refactor-Safe Mocks / Stubs that Allow Renaming
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- deno, typescript
- Lĩnh vực
- testing
Hướng nghiên cứu
Bắt đầu với phần mocking một phần trong hướng dẫn mocking của Deno và xem xét các dự án được tham chiếu là jest-mock-extended, ts-mockito và strong-mock. Không xác định được tệp triển khai hoặc điểm vào của kiểm thử, vì vậy trước tiên hãy tìm các API mocking và các kiểm thử hiện có trong repository này, sau đó xác định hành vi mock được hỗ trợ và phạm vi bao phủ trước khi triển khai.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is your feature request related to a problem? Please describe.
Currently we get type hinting when stubbing like having autocomplete for instance methods/properties on an object. But if those names are ever refactored the test code does not update propertly.
Describe the solution you'd like
I would love to see a solution like:
This binds typing to the original class, so refactors like renaming then update throughout tests.
Example
describe('Party Tests', () => {
test('Mock out an interface', () => {
const mock = mock<PartyProvider>();
mock.start('disco party');
expect(mock.start).toHaveBeenCalledWith('disco party');
});
test('mock out a return type', () => {
const mock = mock<PartyProvider>();
mock.getPartyType.mockReturnValue('west coast party');
expect(mock.getPartyType()).toBe('west coast party');
});
Describe alternatives you've considered
as unknown as Class Pattern
We've tried the as unknown as Class pattern, but it's ugly and doesn't necessarily solve this problem.
This allows us to push partially mocked instances/classes through dependency injection.
export function createMockClient(): SomeClient {
return {
getWords: () => Promise.resolve(undefined),
} as unknown as SomeClient;
}
TS Mockito
This library is fairly great, but it's not well maintained, and I would prefer to have something out-of-the-box with deno. I've also never been a huge fan of the when then pattern that it utilizes for stubbing, but it's modeled after Java Mockito and I imagine it's fairly opinionated. I've seen reasons of the when then pattern, but in my experience it just causes confusion during testing when something doesn't get called even though you're calling it. I would rather setup for a test, and if something hasn't been mocked it could error out. Maybe better messaging is key. I know the when pattern helps set expectations, but I would rather just "expect" them in my test and validate what was called.
Strong Mock
Seems promising, very much like ts-mockito, just not a lot of adoption yet it seems, but at least it seems to be maintained.
Other Thoughts
Ultimately typesafe testing in Deno feels a bit janky, between potentially lock of documentation/examples, and fighting the ES6 import system. I'm used to being able to mock out imports before a library brings the dependency in. I feel that you shouldn't have to fight the system in place, that you should be able to lean into your underlying basics of JS, you shouldn't need to introduce patterns like dependency injection (even though they are great patterns that help testing), you shouldn't need to reinvent a dependency injection container when ES6's import system is good enough.
I know there's a "partial mocking" section in the documentation, but I would rather have an empty shell that I explicitly mock out parts that are needed, rather than take a working instance and individually mocking out parts. This seems like it opens you up to potential issues with actual code in place. https://docs.deno.com/examples/mocking_tutorial/#partial-mocking This also still doesn't solve the renaming issue.
Other Things I've Looked Into
- https://www.npmjs.com/package/ts-mock-imports
- https://www.npmjs.com/package/ts-sinon not maintained, bus factor of one
- Ngôn ngữ chính
- TypeScript
- Star
- 3.6k
- Fork
- 713
- 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
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của denoland/std
-
`assertEquals` throws on structurally equal `Error` objects due to different stack traceCó thể đã có người làm @powerman2026 đã nhận 1 ngày trước. Đang mởbug needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
streams: DelimiterStream leaves delimiter bytes in the output when the delimiter spans more than two chunksCó thể đã có người làm @helmipradita đã nhận 15 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
@std/encoding: decodeAscii85 corrupts delimited data ending in "<", decodeVarint32 reads past the end of the bufferCó thể đã có người làm @helmipradita đã nhận 16 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
@std/yaml: stringify() with condenseFlow wraps already quoted keys in a second pair of quotesCó thể đã có người làm @sebxt đã nhận 35 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
@std/ini parse silently drops an entire section when the section name repeatsCó thể đã có người làm @Harsh23Kashyap đã nhận 35 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày
-
security: set top-level least-privilege permissions in five workflowsCó thể đã có người làm @JonathanTSilva đã nhận hôm nay. Đang mởpriority: p2 size: xs type: security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
JonathanTSilva/jts-website#150 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] SETUP.md is out of dateĐang mởbug Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
scottbenton/Iron-Link#437 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
speakeasy-api/speakeasy#2159 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
vercel-labs/ui#1066 ·
Maintainer thường phản hồi trong vòng 1 ngày