Hi all, I've just added a comment to a review and I think I'd like to ask for a broader discussion of whether I'm correct.
The review is here: https://review.openstack.org/#/c/284857/2 It boils down to: when testing code that uses a promise, should we *use* a promise to have the follow-on callback invoked, or should we mock/spy and then manually perform the same action the promise would if resolved? The two forms are, broadly, pretending that a promise fired: it('successful submit calls the successCallback', function() { *var successFunc = {success: angular.noop};* *spyOn(successFunc, 'success');* spyOn(nova, 'createKeypair')*.and.returnValue(successFunc);* spyOn(toastService, 'add').and.returnValue({ add: angular.noop }); ctrl.submit(); *var successCallback = successFunc.success.calls.argsFor(0)[0];* *var data = {name: 'newKeypair'};* *successCallback(data);* expect(toastService.add).toHaveBeenCalledWith( 'success', 'Successfully imported key pair newKeypair.' ); }); or actually using a promise and making it fire: it('should load container contents', function test() { *var deferred = $q.defer();* spyOn(swiftAPI, 'getObjects')*.and.returnValue(deferred.promise);* service.selectContainer('spam'); expect(service.containerName).toEqual('spam'); expect(swiftAPI.getObjects).toHaveBeenCalledWith('spam', {delimiter: '/'}); *deferred.resolve({data: {items: ['two', 'items']}});* *$rootScope.$apply();* expect(service.objects).toEqual(['two', 'items']); expect(service.pseudo_folder_hierarchy).toEqual([]); }); Richard
__________________________________________________________________________ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev