How to use the @loopback/testlab.sinon.stub function in @loopback/testlab

To help you get started, we’ve selected a few @loopback/testlab 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 strongloop / loopback-next / examples / todo-list / src / __tests__ / unit / controllers / todo-list-todo.controller.unit.ts View on Github external
aListOfTodos = [
      aTodoWithId,
      givenTodo({
        id: 2,
        title: 'do another thing',
      }),
    ] as Todo[];
    aTodoToPatchTo = givenTodo({
      title: 'revised thing to do',
    });
    aChangedTodo = givenTodo({
      id: aTodoWithId.id,
      title: aTodoToPatchTo.title,
    });

    todos = sinon
      .stub()
      .withArgs(aTodoListWithId.id!)
      .returns(constrainedTodoRepo);

    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    (todoListRepo as any).todos = todos;

    // Setup CRUD fakes
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    ({create, find, patch, delete: del} = constrainedTodoRepo.stubs as any);

    controller = new TodoListTodoController(todoListRepo);
  }
});
github strongloop / loopback-next / packages / repository / src / __tests__ / unit / mixins / repository.mixin.unit.ts View on Github external
function setupTestHelpers() {
      app = new AppWithRepoMixin();

      migrateStub = sinon.stub().resolves();
      updateStub = sinon.stub().resolves();

      DataSourceStub = class extends juggler.DataSource {
        automigrate(models: string | string[]): Promise {
          return migrateStub(models);
        }

        autoupdate(models: string | string[]): Promise {
          return updateStub(models);
        }
      };
    }
  });
github strongloop / loopback-next / examples / todo / src / __tests__ / unit / controllers / todo.controller.unit.ts View on Github external
aTodoWithId = givenTodo({
      id: 1,
    });
    aListOfTodos = [
      aTodoWithId,
      givenTodo({
        id: 2,
        title: 'so many things to do',
      }),
    ] as Todo[];
    aChangedTodo = givenTodo({
      id: aTodoWithId.id,
      title: 'Do some important things',
    });

    geoService = {geocode: sinon.stub()};
    geocode = geoService.geocode as sinon.SinonStub;

    controller = new TodoController(todoRepo, geoService);
  }
});
github strongloop / loopback-next / examples / log-extension / src / __tests__ / log-spy.ts View on Github external
export function createConsoleStub(): LogStub {
  return sinon.stub(console, 'log');
}