It is working fine however, we are unable to unit test this code as we are not able to mock the headless service. Since a new instance of the headless service is created in ngOnInit we are not able to mock it. Is it possible to inject the headless service in the component so that we can provide a mock implementation in the unit tests?
š Reproduction steps
create a component in angular and import novu headless and its functions like initializeSession, fetchNotifications, listenNotificationRead, etc.
write unit test cases for the component in spec.ts file
š Expected behavior
it should successfully run all the unit test cases without any failures/errors.
š Actual Behavior with Screenshots
Not able to mock the headless service. Since a new instance of the headless service is created in ngOnInit we are not able to mock it. Is it possible to inject the headless service in the component so that we can provide a mock implementation in the unit tests?
Novu version
"@novu/headless": "^0.24.0"
npm version
10.2.4
node version
18.19.1
š Provide any additional context for the Bug.
No response
š Have you spent some time to check if this bug has been raised before?
š Description
We have configured Novu headless mode and initialized headless service in an Angular component as follows:
`export class NotificationDialogComponent implements OnInit { headlessService: any; constructor(private authService: AuthService {}
ngOnInit(): void { this.authService .loadUserProfile() .then(() => { this.headlessService = new HeadlessService({ applicationIdentifier: environment.novuConfig.applicationIdentifier, subscriberId: this.email, backendUrl: environment.novuConfig.backendUrl, socketUrl: environment.novuConfig.socketUrl, }); this.initSession(); }) .catch(); }
initSession() { this.headlessService.initializeSession({ listener: (res: FetchResult) => {
console.log('welcome to novu headless service', res);
},
onSuccess: (session: ISession) => {
console.log(session, 'Success');
},
onError(error: any) {
console.log(error, 'ERROR');
},
});
}
}`
It is working fine however, we are unable to unit test this code as we are not able to mock the headless service. Since a new instance of the headless service is created in ngOnInit we are not able to mock it. Is it possible to inject the headless service in the component so that we can provide a mock implementation in the unit tests?
š Reproduction steps
š Expected behavior
it should successfully run all the unit test cases without any failures/errors.
š Actual Behavior with Screenshots
Not able to mock the headless service. Since a new instance of the headless service is created in ngOnInit we are not able to mock it. Is it possible to inject the headless service in the component so that we can provide a mock implementation in the unit tests?
Novu version
"@novu/headless": "^0.24.0"
npm version
10.2.4
node version
18.19.1
š Provide any additional context for the Bug.
No response
š Have you spent some time to check if this bug has been raised before?
š¢ Have you read the Contributing Guidelines?
Are you willing to submit PR?
None