#Any way to test private logger?

8 messages · Page 1 of 1 (latest)

fiery mirage
#

I'm following the recommendation on the guide, and have a logger like this. When I'm testing the service, is there any way to test if the logger is called?

#

Testing with jest btw

fierce remnant
#

Technically, yes, but it's not pretty because private entities usually aren't tested

fiery mirage
#

So would the best practice be to inject a logger service?

fierce remnant
#

Personally, I think so. I dislike using new unless I'm creating a provider with it. If I'm in another provider I like to avoid the new keyword when possible

fiery mirage
#

got it, thank you.

idle herald
#

Wouldn't useLogger with a mock logger on the testing module work? The private logger will call the mocked logger underneath, on which you can intercept the calls

fierce remnant
#

I believe that would work if you really wanted to test the private logger.