Skip to content

Unable to properly mock JSNLog when working with documented usage in Angular 6 #180

@mkoziel2000

Description

@mkoziel2000

I found it nearly impossible to unit test components in Angular 6 that took advantage of JSNLog. The reason was in the usage of the global function used to retrieve a JL.JSNLogLogger object. The suggested approach based on existing documentation was to call JL() for each message that is to get logged. I could not find a way to get unit test frameworks like jasmine to properly override this global function during the unit test cycle.

I had to resort to passing in JL.JSNLogLogger as an injectable constructor parameter into my component and then using the private property to get access to the methods. This allowed for logging to get properly mocked. However, it reduced the value of JSNLog because I didn't have control at the component level over the optional parameter that could be passed into JL().

At the very least, it would be nice to have better documentation on the best practice for using JSNLog in Angular 2+ environments whereby it can be easily mocked for unit testing purposes along with examples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions