Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ".toBeCalled" and ".toHaveBeenCalled"?

Tags:

jestjs

When should each of these methods be called, and why?

const spyStart = spyOn(el, 'func1');
expect(spyStart).toHaveBeenCalled();


const spyStart = spyOn(el, 'func1');
expect(spyStart).toBeCalled();
like image 271
YTG Avatar asked Jul 28 '20 08:07

YTG


Video Answer


1 Answers

Actually .toBeCalled is an alias to .toHaveBeenCalled, so they do the same thing.

From the docs:

.toHaveBeenCalled() Also under the alias: .toBeCalled()

like image 193
Влад Степанов Avatar answered Oct 23 '22 00:10

Влад Степанов