Logger component in LWC - need more info on implementation #450
Replies: 2 comments 2 replies
-
@dbrennan008 when you use packaged dependencies - like Nebula's import Logger from 'c/logger';
jest.mock(
'c/logger',
() => ({
error: jest.fn(),
saveLog: jest.()
}),
{ virtual: true }
); Or something to that effect; you would then be able to say assert on the mocked version of expect(Logger.error).toHaveBeenCalled();
// additional asserts about what's been passed to the error function, plus that saveLog was called |
Beta Was this translation helpful? Give feedback.
-
Here is a sample simple test and I am getting Assert Violation: c() 2nd argument Ctor must be a function. @jamessimone import { createElement } from "lwc"; jest.mock( describe('c-my-component', () => { it('should log error and save log', () => {
}); |
Beta Was this translation helpful? Give feedback.
-
I am fairly new to LWC and I am trying to use nebula logger in our LWC components.
Installed unlocked package in our sandbox dev env.
When I try to run jest test --> node ./node_modules/@salesforce/sfdx-lwc-jest/bin/sfdx-lwc-jest contactCreate.test.js
I am getting the following error
Cannot find module 'c/logger' from 'contact-app/main/default/lwc/contactCreate/contactCreate.html'
I have included the following at the top of my template markup
And I am trying to use the following in .js
I am sure I am missing something really basic here, do I need to include something in my package.json? or something? can someone please help..
Beta Was this translation helpful? Give feedback.
All reactions