Comunica
    Preparing search index...
    • Creates a mock function similar to jest.fn but also tracks calls to object[methodName]

      Note: By default, jest.spyOn also calls the spied method. This is different behavior from most other test libraries.

      Type Parameters

      Parameters

      • object: T
      • method: Key
      • accessType: A

      Returns A extends "set"
          ? SpyInstance<void, [Value], any>
          : A extends "get"
              ? SpyInstance<Value, [], any>
              : Value extends Constructor
                  ? SpyInstance<
                      InstanceType<Value<Value>>,
                      ConstructorArgsType<Value<Value>>,
                      any,
                  >
                  : Value extends Func
                      ? SpyInstance<ReturnType<Value<Value>>, ArgsType<Value<Value>>, any>
                      : never

      const video = require('./video');

      test('plays video', () => {
      const spy = jest.spyOn(video, 'play');
      const isPlaying = video.play();

      expect(spy).toHaveBeenCalled();
      expect(isPlaying).toBe(true);

      spy.mockReset();
      spy.mockRestore();
      });
    • Creates a mock function similar to jest.fn but also tracks calls to object[methodName]

      Note: By default, jest.spyOn also calls the spied method. This is different behavior from most other test libraries.

      Type Parameters

      • T extends {}
      • M extends string | number | symbol

      Parameters

      • object: T
      • method: M

      Returns ConstructorProperties<Required<T>>[M] extends new (...args: any[]) => any
          ? SpyInstance<
              InstanceType<any[any]>,
              ConstructorArgsType<any[any]>,
              any,
          >
          : never

      const video = require('./video');

      test('plays video', () => {
      const spy = jest.spyOn(video, 'play');
      const isPlaying = video.play();

      expect(spy).toHaveBeenCalled();
      expect(isPlaying).toBe(true);

      spy.mockReset();
      spy.mockRestore();
      });
    • Creates a mock function similar to jest.fn but also tracks calls to object[methodName]

      Note: By default, jest.spyOn also calls the spied method. This is different behavior from most other test libraries.

      Type Parameters

      • T extends {}
      • M extends string | number | symbol

      Parameters

      • object: T
      • method: M

      Returns FunctionProperties<Required<T>>[M] extends Func
          ? SpyInstance<ReturnType<any[any]>, ArgsType<any[any]>, any>
          : never

      const video = require('./video');

      test('plays video', () => {
      const spy = jest.spyOn(video, 'play');
      const isPlaying = video.play();

      expect(spy).toHaveBeenCalled();
      expect(isPlaying).toBe(true);

      spy.mockReset();
      spy.mockRestore();
      });