javascript - Typescript Jasmine toHaveBeenCalledTimes() is not a function -
i have test in typescript application:
it("should send current state when new subscriber added (watching on file)", () => { runs(() => { flag = false; subscriber = createspyobj<ipathwatchsubscriber>("pathwatchsubscribermock", ["processnotifyaction"]); subscriber2 = createspyobj<ipathwatchsubscriber>("pathwatchsubscribermock", ["processnotifyaction"]); pathwatch.subscribe(subscriber); pathwatch.watch(filepath); pathwatch.subscribe(subscriber2); w(() => { flag = true; }); }); waitsfor((): boolean => { return flag; }, "failure", chokidaroperationdelay); runs(() => { expect(subscriber.processnotifyaction).tohavebeencalledwith(expectednotifyaction); expect(subscriber.processnotifyaction).tohavebeencalledtimes(2); expect(subscriber2.processnotifyaction).tohavebeencalledwith(expectednotifyaction); }); } );
when compile js, there no errors. when run it, have following error:
typeerror: expect(...).tohavebeencalledtimes not function
how test, how many times function of spyobj called? in advance.
take here , , go section of "other tracking properties"
you can try using .calls.count()
property.
so test becomes: expect(subscriber.processnotifyaction.calls.count()).toequal(2)
side note - of course assuming version of jasmine supports this, should unless have old version of jasmine.
Comments
Post a Comment