samedi 30 avril 2016

How to catch $broadcast in spyOn?

I don't know why my testing is not working.

it('should be called when "get-tentative-events" is fired', function() {
  spyOn(this.VM, 'addEvents');
  spyOn(this.VM, 'setEventData').and.returnValue(null);

  this.VM.$root.$broadcast('get-tentative-events', []);
  expect(this.VM.addEvents).toBeDefined();
  expect(this.VM.addEvents).toHaveBeenCalled();
});

In debugging, I confirmed addEvents is called.
But there was a error single-calendar addEvents should be called when "get-tentative-events" is fired FAILED

FYI:

if I change

this.VM.$root.$broadcast('get-tentative-events', []);

to

this.VM.addEvents([])

I can pass this test.So I can not understand why my test is failing.

Aucun commentaire:

Enregistrer un commentaire