How to use the @ngneat/spectator.installProtoMethods function in @ngneat/spectator

To help you get started, we’ve selected a few @ngneat/spectator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ngneat / spectator / projects / spectator / jest / src / lib / mock.ts View on Github external
export function createSpyObject(type: InjectableType, template?: Partial>): SpyObject {
  const mock: any = { ...template } || {};

  installProtoMethods(mock, type.prototype, () => {
    const jestFn = jest.fn();
    const newSpy: CompatibleSpy = jestFn as any;

    newSpy.andCallFake = (fn: Function) => {
      jestFn.mockImplementation(fn as (...args: any[]) => any);

      return newSpy;
    };

    newSpy.andReturn = (val: any) => {
      jestFn.mockReturnValue(val);
    };

    newSpy.reset = () => {
      jestFn.mockReset();
    };
github ngneat / spectator / projects / spectator / jest / src / lib / mock.ts View on Github external
export function createSpyObject(type: InjectableType, template?: Partial>): SpyObject {
  const mock: any = template || {};

  installProtoMethods(mock, type.prototype, () => {
    const jestFn = jest.fn();
    const newSpy: CompatibleSpy = jestFn as any;

    newSpy.andCallFake = (fn: Function) => {
      jestFn.mockImplementation(fn as (...args: any[]) => any);

      return newSpy;
    };

    newSpy.andReturn = (val: any) => {
      jestFn.mockReturnValue(val);
    };

    newSpy.reset = () => {
      jestFn.mockReset();
    };