<div dir="ltr">Hi all,<div><br></div><div>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.</div><div><br></div><div>The review is here: <a href="https://review.openstack.org/#/c/284857/2">https://review.openstack.org/#/c/284857/2</a></div><div><br></div><div>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?</div><div><br></div><div>The two forms are, broadly, pretending that a promise fired:</div><div><br></div><div><div>      it('successful submit calls the successCallback', function() {</div><div>        <b>var successFunc = {success: angular.noop};</b></div><div>        <b>spyOn(successFunc, 'success');</b></div><div>        spyOn(nova, 'createKeypair')<b>.and.returnValue(successFunc);</b></div><div>        spyOn(toastService, 'add').and.returnValue({ add: angular.noop });</div><div>        ctrl.submit();</div><div>        <b>var successCallback = successFunc.success.calls.argsFor(0)[0];</b></div><div>        <b>var data = {name: 'newKeypair'};</b></div><div>        <b>successCallback(data);</b></div><div>        expect(toastService.add).toHaveBeenCalledWith(</div><div>            'success',</div><div>            'Successfully imported key pair newKeypair.'</div><div>        );</div><div>      });</div></div><div><br></div><div>or actually using a promise and making it fire:</div><div><br></div><div><div>    it('should load container contents', function test() {</div><div>      <b>var deferred = $q.defer();</b></div><div>      spyOn(swiftAPI, 'getObjects')<b>.and.returnValue(deferred.promise);</b></div><div>      service.selectContainer('spam');</div><div>      expect(service.containerName).toEqual('spam');</div><div>      expect(swiftAPI.getObjects).toHaveBeenCalledWith('spam', {delimiter: '/'});</div><div>      <b>deferred.resolve({data: {items: ['two', 'items']}});</b></div><div>      <b>$rootScope.$apply();</b></div><div>      expect(service.objects).toEqual(['two', 'items']);</div><div>      expect(service.pseudo_folder_hierarchy).toEqual([]);</div><div>    });</div></div><div><br></div><div><br></div><div>     Richard</div><div><br></div></div>