You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered: