MarkBind / markbind

MarkBind is a tool for generating content-heavy websites from source files in Markdown format
https://markbind.org/
MIT License
134 stars 123 forks source link

Create manual mock for logger #2466

Closed luminousleek closed 3 months ago

luminousleek commented 3 months ago

Please confirm that you have searched existing issues in the repo

Yes, I have searched the existing issues

Any related issues?

2099

What is the area that this feature belongs to?

Testing

Is your feature request related to a problem? Please describe.

To test for logger input, the logger is mocked and then calls to the logger are checked (see #2463 for an example). However, this must be done every for every file that the logger is mocked in, which is a bit annoying.

Describe the solution you'd like

Create a manual mock of the logger, so that we can just call jest.mock('logger'); at the start of each test. The default implementation of manual mocks can also be overridden though it's a bit more finnicky to do so.

Describe alternatives you've considered

No response

Additional context

No response

kaixin-hc commented 3 months ago

Cool suggestion, I think this makes sense if the setup code for the logger is long. Just wondering which functions you want to mock with the logger? If the mock is just warn, info, error for example, there might be an argument made for mocking them at the start of each test case instead so that the tests are totally independent and not based on outside "logic"

luminousleek commented 3 months ago

Cool suggestion, I think this makes sense if the setup code for the logger is long. Just wondering which functions you want to mock with the logger? If the mock is just warn, info, error for example, there might be an argument made for mocking them at the start of each test case instead so that the tests are totally independent and not based on outside "logic"

Actually after thinking and reading about this a bit more I realise there isn't much need to do a manual mock for the logger since as discussed in #2099 it makes more sense to test for logger calls than logger outputs. So the automatic mock of jest.mock('/path/to/logger'); would work just fine since it replaces all the methods with another method that just returns undefined.

I think I'll close this issue then.