Assume I have a class Foo
that looks like this:
class Foo {
bar() {
return 'bar';
}
}
Let's say I want to mock the method bar
. Is there a reason to prefer one of these over the other?
jest.spyOn(Foo.prototype, 'bar').mockImplementation(() => 'baz');
vs
Foo.prototype.bar = jest.fn().mockImplementation(() => 'baz');
I tried both, and they seem to be identical.