Replies: 2 comments 3 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.
-
It would be cool if Deno would support possibility to mock/stub imported es modules, as well as global variables like
Deno
etc. 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.js
I would love to, without having to modify this code, simply create
test
with option to override imports/global variables:main.test.js
Such code would mimick
deno run path/to/main.ts noMainParameter
with 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 mine
code without having to touch already written code base. I would also needresult
object 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.js
module 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