Try the following:
describe('W2History controller', function () { var controller, scope, modal; var fakeModal = { result: { then: function (confirmCallback, cancelCallback) { //Store the callbacks for later when the user clicks on the OK or Cancel button of the dialog this.confirmCallBack = confirmCallback; this.cancelCallback = cancelCallback; } }, close: function (item) { //The user clicked OK on the modal dialog, call the stored confirm callback with the selected item this.result.confirmCallBack(item); }, dismiss: function (type) { //The user clicked cancel on the modal dialog, call the stored cancel callback this.result.cancelCallback(type); } }; var modalOptions = { templateUrl: '/n/views/consent.html', controller: 'W2ConsentModal as w2modal', resolve: { employee: jasmine.any(Function) }, size: 'lg' }; var actualOptions; beforeEach(function () { module('plunker'); inject(function (_$controller_, _$rootScope_, _$modal_) { scope = _$rootScope_.$new(); modal = _$modal_; spyOn(modal, 'open').and.callFake(function(options){ actualOptions = options; return fakeModal; }); controller = _$controller_('W2History', { $scope: scope, $modal: modal }); }); }); it('Should correctly show the W2 consent modal', function () { var employee = { name : "test"}; controller.showModal(employee); expect(modal.open).toHaveBeenCalledWith(modalOptions); expect(actualOptions.resolve.employee()).toEqual(employee); }); });
Plunk
Explanation
We should not expect the actual resolve.employee be the same as the fake resolve.employee , because resolve.employee is a function that returns the employee (in this case, the employee is delayed in closing). The function may be the same, but at run time, the returned objects may be different.
The reason your test fails is because javascript compares functions. Take a look at the fiddle . In any case, this does not bother me, because we should not expect the implementation of functions . In this case, we take care that resolve.employee returns the same object that we are passing:
expect(actualOptions.resolve.employee()).toEqual(employee);
So, the solution is here: We expect everything except resolve.employee :
var modalOptions = { templateUrl: '/n/views/consent.html', controller: 'W2ConsentModal as w2modal', resolve: { employee: jasmine.any(Function)
Check resolve.employee separately by first pinning it:
var actualOptions; spyOn(modal, 'open').and.callFake(function(options){ actualOptions = options;