question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a convenient way for mocking

See original GitHub issue

CONTEXT: 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:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
Qix-commented, May 15, 2017

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?

0reactions
LeoArefcommented, May 15, 2017

Ok, thanks a lot for your input 👍

Currently I’m testing that it’s working without issues and calling console.log with the given text, I also think that’s enough!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found