Replies: 6 comments 10 replies
-
|
I'm surprised nobody has engaged with this comment. The inability to use jest-style module mocking is baffling to me. I've already spent way more time trying to figure out how to do this very simple thing, than setting up a full testing flow in Node + jest would have taken. And IF this functionality exists, then its documentation must be poor or non-existent because no search, ChatGPT, nor any other system has been able to find any reference to Deno's ability to do this. You mean the @std/testing/mock library? Yeah it doesn't mock an import by replacing it. If I want to do that, I have to use a custom import map and re-create the entire import surface of my project, which is quite large. All the library does is give me the tools to completely rebuild every library I import. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for bumping this! I come from .NET world where I always had to design my architecture in a way that allows to test the code in future (setup IoC containers etc.). This is huge overhead. When I start some new project I prefer much more to focus on "making it happen", iterate quickly and when final shape is ready I would like to focus on testing. Ability to pick up any file and test it thoroughly by mocking all global variables/imports would be an amazing feature and IMHO perfect selling point to convince people to start using Deno. |
Beta Was this translation helpful? Give feedback.
-
|
I try to move to deno atm. I have a monorepo which I would like to move. But I stronlgy use import mocking for my tests. I was hoping that "scopes" might be a soltion in order to have a kind of override for the imports. |
Beta Was this translation helpful? Give feedback.
-
|
FWIW (just one developer) this is the main issue discouraging me from adopting Deno. With the focus on security, simplicity, and types, I feel like the team is positioning Deno as a runtime that facilitates better engineering, and I really appreciate that. In my opinion, testing is a big part of better engineering in many settings, and I think import mocks are basically necessary to do any significant amount of JS testing. Also, one thing that LLM's are really good at is writing specs, so I think we are also seeing the cost/benefit of writing tests improve substantially. Many existing Node based projects also rely heavily on import mocking, and not having the feature available in Deno is going to block migration. |
Beta Was this translation helpful? Give feedback.
-
|
I second opinions above. It's giving me headaches trying to mock dependencies properly using Deno. |
Beta Was this translation helpful? Give feedback.
-
|
Bumping up. Landed here after struggling with modules mocking. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It would be cool if Deno would support possibility to mock/stub imported es modules, as well as global variables like
Denoetc. in unit/integration tests. My point is: I start coding some project, I don't focus on unit testing at all, as I don't know the final shape of the code, I want to iterate fast, etc. Once my project is in some meaningful shape, I end up with code like (pseudocode):main.jsI would love to, without having to modify this code, simply create
testwith option to override imports/global variables:main.test.jsSuch code would mimick
deno run path/to/main.ts noMainParameterwith all dependencies mocked. Result object would have all stdout and stderr in plain string format so I can assert against program output. Basically, I would love to be able to stub allnot minecode without having to touch already written code base. I would also needresultobject to contain all helpers regarding output of my application, like stdout, network calls etc. This sounds quite challenging even to define, so I'm I would just like to start discussion. Nowadays, the way how I solve it is by introducingdeps.jsmodule which I import in my original code base (this means I need to refactor already working code) and then, I can override specific properties inside tests. It would be cool to avoid touching original code base, and build tests on-top of existing solution.Beta Was this translation helpful? Give feedback.
All reactions