0

I have a constructor (myLibrary) that calls an _init method when it is instantiated using the new keyword. I have a jasmine test to check that the _init method is called:

it('should call _init method on instantiation', function () {
    var test = new myLibrary();
    spyOn(test, "_init");
    expect(test._init).toHaveBeenCalled();
});

but this isn't working. I get an error when the test runs:

Expected spy _init to have been called

I'm thinking this because doing var test = new library() has already run the _init before I've even created the spy? If this is the case how do i get around this?

Mike Rifgin
  • 9,850
  • 20
  • 70
  • 109

0 Answers0