jest spyon

JavaScript
// jest.spyOn(object, methodName)
const spy = jest.spyOn(video, 'play');

// jest.spyOn(object, methodName, accessType?)
const spy = jest.spyOn(video, 'play', 'get'); // we pass 'get'//class.js
class MyClass {
  methodOne() {
    return 1;
  }
  methodTwo() {
    return 2;
  }
}
module.exports = MyClass;

// class.test.js
test('spy using class method', () => {
  const result = new MyClass()
  const spy = jest.spyOn(result, 'methodOne')
  result.methodOne()

  // check class method is call or not
  expect(spy).toHaveBeenCalled()

  // expect old value
  expect(result.methodOne()).toBe(1)

  // expect new value
  spy.mockReturnValueOnce(12)
  expect(result.methodOne()).toBe(12)
})
Source

Also in JavaScript: