Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Update:</h2> <p>I wasn't able to solve your specific problem. Mostly because I couldn't get angular-seed going/it was taking forever, but I thought I'd make my answer more complete.</p> <p>There are 2 ways to solve this problem in general:</p> <ol> <li>Spy on a function other than the one being triggered by some event/intermediary</li> <li>Spy on the prototype of the function before the object is created. In other words: <code>spyOn(MyObjectNamespace.Class.prototype, 'functionToSpyOn')</code></li> </ol> <p>Afterwards just restore and you should be fine. </p> <hr> <p>I am only vaguely familiar with angular, but have experienced similar problems. </p> <h2>Solution 1</h2> <p>You can just separate out the function rather than specifying it anonymously. This helps test your functionality specifically and avoid all the angular stuff. </p> <h2>Solution 2</h2> <p>Sometimes with frameworks this isn't possible. The main problem here is that your spy is attaching itself too late and the reference is lost or gets overridden.</p> <p>Test:</p> <pre><code>describe('directives', function() { beforeEach(module('directives')); describe('popOver', function() { var $scope, compile, location, $httpBackend, elm; beforeEach(inject(function($rootScope, $compile, _$httpBackend_) { $scope = $rootScope.$new(); compile = $compile; $httpBackend = _$httpBackend_; elm = angular.element('&lt;i class="pop-over" data-placement="top" data-chatid="testChatId" &gt; &lt;/i&gt;'); compile(elm)($scope); })); it('should call element.popover()', function() { var popoverFunction = $.fn.popover; $httpBackend.expectGET('someurl/testChatId.json'). respond([ {firstName: 'test', lastName: 'user'}]); spyOn($.fn, 'popover').andCallThrough(); elm.trigger('mouseover'); $httpBackend.flush(); expect($.fn.popover).toHaveBeenCalled(); //restore popover, use sinon's restore fn instead here $.fn.popover = popoverFunction }); }); }); </code></pre> <p>You can use Sinon with Jasmine. Sinon has a spy.restore function that gets rid of the first and last line for you. In my own tests I've placed the first line and the spy creation in a beforeEach and the restore in an afterEach.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload