How to use the @loopback/testlab.sinon.assert 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 / boot / src / __tests__ / unit / booters / repository.booter.unit.ts View on Github external
it('gives a warning if called on an app without RepositoryMixin', async () => {
    const normalApp = new Application();
    await sandbox.copyFile(
      resolve(__dirname, '../../fixtures/multiple.artifact.js'),
    );

    const booterInst = new RepositoryBooter(
      normalApp as ApplicationWithRepositories,
      SANDBOX_PATH,
    );

    // Load uses discovered property
    booterInst.discovered = [resolve(SANDBOX_PATH, 'multiple.artifact.js')];
    await booterInst.load();

    sinon.assert.calledOnce(stub);
    sinon.assert.calledWith(
      stub,
      'app.repository() function is needed for RepositoryBooter. You can add it ' +
        'to your Application using RepositoryMixin from @loopback/repository.',
    );
  });
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / router / reject.provider.unit.ts View on Github external
it('logs the error', async () => {
    const logger = sinon.spy() as LogError & SinonSpy;
    const reject = new RejectProvider(logger).value();

    reject(contextStub, testError);
    await contextStub.result;

    sinon.assert.calledWith(logger, testError, 500, contextStub.request);
  });
github strongloop / loopback-next / examples / todo-list / src / __tests__ / unit / controllers / todo-list-todo.controller.unit.ts View on Github external
it('creates a todo on a todoList', async () => {
      create.resolves(aTodoWithId);
      expect(await controller.create(aTodoListWithId.id!, aTodo)).to.eql(
        aTodoWithId,
      );
      sinon.assert.calledWith(todos, aTodoListWithId.id!);
      sinon.assert.calledWith(create, aTodo);
    });
  });
github strongloop / loopback-next / packages / repository / src / __tests__ / unit / repositories / relations-helpers / find-by-foreign-keys.unit.ts View on Github external
it('returns an empty array when no instances have the foreign key values', async () => {
    const find = productRepo.stubs.find;
    find.resolves([]);
    await productRepo.create({id: 1, name: 'product', categoryId: 1});
    const products = await findByForeignKeys(productRepo, 'categoryId', [2, 3]);
    expect(products).to.be.empty();
    sinon.assert.calledWithMatch(find, {});
  });
github strongloop / loopback-next / packages / repository / src / __tests__ / unit / mixins / repository.mixin.unit.ts View on Github external
it('calls autoupdate on registered datasources', async () => {
      app.dataSource(DataSourceStub);

      await app.migrateSchema({existingSchema: 'alter'});

      sinon.assert.called(updateStub);
      sinon.assert.notCalled(migrateStub);
    });
github strongloop / loopback-next / packages / boot / src / __tests__ / unit / booters / datasource.booter.unit.ts View on Github external
it('gives a warning if called on an app without RepositoryMixin', async () => {
    const normalApp = new Application();
    await sandbox.copyFile(
      resolve(__dirname, '../../fixtures/datasource.artifact.js'),
    );

    const booterInst = new DataSourceBooter(
      normalApp as ApplicationWithRepositories,
      SANDBOX_PATH,
    );

    booterInst.discovered = [resolve(SANDBOX_PATH, 'datasource.artifact.js')];
    await booterInst.load();

    sinon.assert.calledOnce(stub);
    sinon.assert.calledWith(
      stub,
      'app.dataSource() function is needed for DataSourceBooter. You can add ' +
        'it to your Application using RepositoryMixin from @loopback/repository.',
    );
  });
github strongloop / loopback-next / packages / boot / src / __tests__ / unit / booters / datasource.booter.unit.ts View on Github external
it('gives a warning if called on an app without RepositoryMixin', async () => {
    const normalApp = new Application();
    await sandbox.copyFile(
      resolve(__dirname, '../../fixtures/datasource.artifact.js'),
    );

    const booterInst = new DataSourceBooter(
      normalApp as ApplicationWithRepositories,
      SANDBOX_PATH,
    );

    booterInst.discovered = [resolve(SANDBOX_PATH, 'datasource.artifact.js')];
    await booterInst.load();

    sinon.assert.calledOnce(stub);
    sinon.assert.calledWith(
      stub,
      'app.dataSource() function is needed for DataSourceBooter. You can add ' +
        'it to your Application using RepositoryMixin from @loopback/repository.',
    );
  });
github strongloop / loopback-next / examples / todo-list / src / __tests__ / unit / controllers / todo-list.controller.unit.ts View on Github external
it('creates a TodoList', async () => {
      const create = todoListRepo.stubs.create;
      create.resolves(aTodoListWithId);
      expect(await controller.create(aTodoList)).to.eql(aTodoListWithId);
      sinon.assert.calledWith(create, aTodoList);
    });
  });
github strongloop / loopback-next / packages / repository / src / __tests__ / unit / repositories / relation.repository.unit.ts View on Github external
it('can find related model instance', async () => {
      const constraint: Partial = {name: 'Jane'};
      const hasManyCrudInstance = givenDefaultHasManyInstance(constraint);
      await hasManyCrudInstance.find({where: {id: 3}});
      sinon.assert.calledWithMatch(customerRepo.stubs.find, {
        where: {id: 3, name: 'Jane'},
      });
    });
github strongloop / loopback-next / examples / log-extension / src / __tests__ / acceptance / log.extension.acceptance.ts View on Github external
expect(spy.called).to.be.False();

    await client.get('/off').expect(200, 'off called');
    expect(spy.called).to.be.False();

    await client.get('/debug').expect(200, 'debug called');
    sinon.assert.calledWith(spy, debugMatch);

    await client.get('/info').expect(200, 'info called');
    sinon.assert.calledWith(spy, infoMatch);

    await client.get('/warn').expect(200, 'warn called');
    sinon.assert.calledWith(spy, warnMatch);

    await client.get('/error').expect(200, 'error called');
    sinon.assert.calledWith(spy, errorMatch);

    await client.get('/?name=test').expect(200, 'hello test');
    sinon.assert.calledWith(spy, nameMatch);
  });