How to Mock JSNLog in Jasmine Unit Tests of Angular Code
One of the development teams at work implemented JSNLog to log from JavaScript in an Angular application we're working on, but even though the documentation to get this set up and running was very clear, the way to get it mocked for unit testing was not . Fortunately, it's not too difficult. The key in getting this to work was to spy on the JL function and have it return a mock with spy methods for the different logging methods (debug(), trace(), etc). Then set it up in your providers declaration. Here's the mock object: export class JLMock { trace = jasmine.createSpy( 'trace' ); debug = jasmine.createSpy( 'debug' ); info = jasmine.createSpy( 'info' ); warn = jasmine.createSpy( 'warn' ); error = jasmine.createSpy( 'error' ); fatal = jasmine.createSpy( 'fatal' )...