Provide a convenient way for mocking
See original GitHub issueCONTEXT: I’m writing a lib, and I’ve a printer
module which uses Chalk for console styling
And I’m trying to write unit tests for the printer
module with mocking Chalk.
I checked the source code searching for a way to mock the lib for my testing, but I couldn’t find a convenient way to do so.
All the colors/background are in the __proto__
property, which is so hard to override (ie. mock), so could you advise the best way to do that?
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Stubbing and Mocking with Mockito and JUnit - Semaphore CI
Learn how to create true unit tests by mocking all external dependencies in your JUnit classes with the help of Mockito.
Read more >Mocking with examples - Postman Learning Center
Postman's mock service uses a matching algorithm to select the most appropriate saved example to return in response to a request. As part...
Read more >To mock or not to mock: is that even a question? - Accenture
Accenture's Steve Bement reveals mocking is a popular approach for handling dependencies while unit testing, but it comes at a cost.
Read more >How to Mock without Providing an Implementation in TypeScript
The whole point is to have a convenient way to generate a mock given an interface, so that developers don't have to manually...
Read more >A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
With Mockito, creating a mock is as easy as calling a static method Mockito.mock() : ... Let's briefly explore the stubbing methods provided...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you’re testing the output of Chalk in your unit tests, you’re being way too specific with your tests and you’ll find their fragility to be a hindrance.
Could you explain a bit more about what you’re trying to mock with chalk?
Ok, thanks a lot for your input 👍
Currently I’m testing that it’s working without issues and calling
console.log
with the giventext
, I also think that’s enough!