As far as I understand, the .toHaveBeenCalled()
Matcher of jasmine returns a Promise which is resolved when the function has been called. Actually for me, it returns undefined:
it('should show the first entries', () => {
expect(contentfulService.first)
.toHaveBeenCalled()
.then(() => {
expect(component.entries).toBe(entriesMock);
});
});
The first
method of the contentfulService is spied on like this:
contentfulService = TestBed.get(ContentfulService);
spyOn(contentfulService, 'first').and.callThrough();
The spec fails telling me:
TypeError: Cannot read property 'then' of undefined
I double checked it. It's definitely the result of toHaveBeenCalled()
that returns undefined. Why? Am I getting something wrong?
Aucun commentaire:
Enregistrer un commentaire