Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Bug Report: Novu Headless Unit Testing Angular #5409

Open
2 tasks done
gPriyanka-GIT opened this issue Apr 15, 2024 · 1 comment
Open
2 tasks done

馃悰 Bug Report: Novu Headless Unit Testing Angular #5409

gPriyanka-GIT opened this issue Apr 15, 2024 · 1 comment

Comments

@gPriyanka-GIT
Copy link

馃摐 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

  1. create a component in angular and import novu headless and its functions like initializeSession, fetchNotifications, listenNotificationRead, etc.
  2. 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?

  • I checked and didn't find a similar issue

馃彚 Have you read the Contributing Guidelines?

Are you willing to submit PR?

None

Copy link

linear bot commented Apr 15, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants