I am looking to verify that when I pass an argument to a function, it is indeed a function reference even though the function reference is passed using the bind()
method.
Take a look at this shortened code snippet that needs to be tested:
initialize: function () {
this.register(this.handler.bind(this));
}
Here is the unit test designed to confirm if register()
was called with handler()
:
it('register handler', function () {
spyOn(bar, 'register');
bar.initialize();
expect(bar.register.calls.argsFor(0)[0]).toEqual(bar.handler);
});
It seems like the argument does not match the function reference possibly due to the use of bind()
- how can I ensure that the correct function reference is being passed while still utilizing the bind()
method?
Disclaimer: Although I mentioned Jasmine, this issue is not exclusive to that framework and is more related to the methods being employed.