How to use the @loopback/testlab.createStubInstance 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 / packages / repository / src / __tests__ / unit / repositories / belongs-to-repository-factory.unit.ts View on Github external
it('throws an error when the target does not have any primary key', () => {
    class Product extends Entity {
      static definition = new ModelDefinition(
        'Product',
      ).addProperty('categoryId', {type: Number});
    }

    class Category extends Entity {
      static definition = new ModelDefinition('Category');
    }

    const productRepo = createStubInstance(DefaultCrudRepository);
    const categoryRepo = createStubInstance(DefaultCrudRepository);

    const relationMeta: BelongsToDefinition = {
      type: RelationType.belongsTo,
      targetsMany: false,
      name: 'category',
      source: Product,
      target: () => Category,
      keyFrom: 'categoryId',
      // Let the relation to look up keyTo as the primary key of Category
      // (which is not defined!)
      keyTo: undefined,
    };

    expect(() =>
      createBelongsToAccessor(
        relationMeta,
github strongloop / loopback-next / packages / repository / src / __tests__ / unit / repositories / belongs-to-repository-factory.unit.ts View on Github external
it('throws an error when the target does not have any primary key', () => {
    class Product extends Entity {
      static definition = new ModelDefinition(
        'Product',
      ).addProperty('categoryId', {type: Number});
    }

    class Category extends Entity {
      static definition = new ModelDefinition('Category');
    }

    const productRepo = createStubInstance(DefaultCrudRepository);
    const categoryRepo = createStubInstance(DefaultCrudRepository);

    const relationMeta: BelongsToDefinition = {
      type: RelationType.belongsTo,
      targetsMany: false,
      name: 'category',
      source: Product,
      target: () => Category,
      keyFrom: 'categoryId',
      // Let the relation to look up keyTo as the primary key of Category
      // (which is not defined!)
      keyTo: undefined,
    };

    expect(() =>
      createBelongsToAccessor(
github strongloop / loopback-next / examples / todo / src / __tests__ / unit / controllers / todo.controller.unit.ts View on Github external
function resetRepositories() {
    todoRepo = createStubInstance(TodoRepository);
    aTodo = givenTodo();
    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',
    });
github strongloop / loopback-next / examples / todo-list / src / __tests__ / unit / controllers / todo-list.controller.unit.ts View on Github external
function resetRepositories() {
    todoListRepo = createStubInstance(TodoListRepository);
    aTodoList = givenTodoList();
    aTodoListWithId = givenTodoList({
      id: 1,
    });
    aListOfTodoLists = [
      aTodoListWithId,
      givenTodoList({
        id: 2,
        title: 'a lot of todos',
      }),
    ] as TodoList[];
    aTodoListToPatchTo = givenTodoList({
      title: 'changed list of todos',
    });
    aChangedTodoList = givenTodoList({
      id: aTodoListWithId.id,
github strongloop / loopback-next / examples / todo-list / src / __tests__ / unit / controllers / todo-list-todo.controller.unit.ts View on Github external
function resetRepositories() {
    todoListRepo = createStubInstance(TodoListRepository);
    constrainedTodoRepo = createStubInstance>(
      DefaultHasManyRepository,
    );

    aTodoListWithId = givenTodoList({
      id: 1,
    });

    aTodo = givenTodo();
    aTodoWithId = givenTodo({id: 1});
    aListOfTodos = [
      aTodoWithId,
      givenTodo({
        id: 2,
        title: 'do another thing',
      }),
github strongloop / loopback-next / examples / todo-list / src / __tests__ / unit / controllers / todo-list-todo.controller.unit.ts View on Github external
function resetRepositories() {
    todoListRepo = createStubInstance(TodoListRepository);
    constrainedTodoRepo = createStubInstance>(
      DefaultHasManyRepository,
    );

    aTodoListWithId = givenTodoList({
      id: 1,
    });

    aTodo = givenTodo();
    aTodoWithId = givenTodo({id: 1});
    aListOfTodos = [
      aTodoWithId,
      givenTodo({
        id: 2,
        title: 'do another thing',
      }),
    ] as Todo[];