Refactor-Safe Mocks / Stubs that Allow Renaming
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- deno, typescript
- Área
- testing
Línea de trabajo
Comienza con la sección de mocking parcial del tutorial de mocking de Deno y revisa los proyectos referenciados jest-mock-extended, ts-mockito y strong-mock. No se identifica ningún archivo de implementación ni punto de entrada de pruebas, así que primero localiza las APIs de mocking y las pruebas existentes en este repositorio y, después, define el comportamiento de mock compatible y la cobertura antes de la implementación.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- TypeScript
- Estrellas
- 3.6k
- Forks
- 713
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de denoland/std
-
`assertEquals` throws on structurally equal `Error` objects due to different stack tracePosiblemente ocupada @powerman2026 la tomó hace 1 día. Abiertobug needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
streams: DelimiterStream leaves delimiter bytes in the output when the delimiter spans more than two chunksPosiblemente ocupada @helmipradita la tomó hace 15 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
-
@std/encoding: decodeAscii85 corrupts delimited data ending in "<", decodeVarint32 reads past the end of the bufferPosiblemente ocupada @helmipradita la tomó hace 16 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
@std/yaml: stringify() with condenseFlow wraps already quoted keys in a second pair of quotesPosiblemente ocupada @sebxt la tomó hace 35 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
@std/ini parse silently drops an entire section when the section name repeatsPosiblemente ocupada @Harsh23Kashyap la tomó hace 35 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
Todos los issues de denoland/std
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
Los mantenedores suelen responder en 1 día
-
security: set top-level least-privilege permissions in five workflowsPosiblemente ocupada @JonathanTSilva la tomó hoy. Abiertopriority: p2 size: xs type: security
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
JonathanTSilva/jts-website#150 ·
Los mantenedores suelen responder en 1 día
-
[BUG] SETUP.md is out of dateAbiertobug Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
scottbenton/Iron-Link#437 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
speakeasy-api/speakeasy#2159 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
vercel-labs/ui#1066 ·
Los mantenedores suelen responder en 1 día