In my current project, I am tasked with testing an application that utilizes an alert to notify the user about its NFC usage. To properly unit test this app, I decided to spy on the alertController.create method using Jasmine like so:
alertController.create = jasmine.createSpy().and.resolveTo({
present: jasmine.createSpy()
});
Now during the unit test, my goal is to verify if the alertController.create method is invoked with the correct alert options:
expect(alertController.create).toHaveBeenCalledWith({
header: 'NFC aan het lezen...',
message: 'Hou de pas tegen de achterkant van de telefoon',
buttons: [
{
text: 'Anuleren',
role: 'cancel',
handler: () => nfc.stopRead()
}
]
});
However, I encountered an error while running the test specifically related to the handler function. How can I effectively ensure that the alertcontroller.create function is called with the accurate values? The test currently outputs the following error:
Expected $[0].buttons[0].handler = Function to equal Function.
I aim to validate whether the provided object matches the expected one but the existing function fails to verify this. Any suggestions on how to address this issue would be greatly appreciated.