How to use the @loopback/testlab.sinon.spy 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 / context / src / __tests__ / unit / binding.unit.ts View on Github external
it('clears cache if _getValue changes', () => {
      const providerSpy = sinon.spy();
      class IndexProvider implements Provider {
        value() {
          return providerSpy();
        }
      }
      const indexBinding = ctx
        .bind('index')
        .toDynamicValue(spy)
        .inScope(BindingScope.SINGLETON);

      ctx.getSync(indexBinding.key);
      sinon.assert.calledOnce(spy);
      spy.resetHistory();

      // Singleton
      ctx.getSync(indexBinding.key);
github strongloop / loopback-next / packages / rest / src / __tests__ / acceptance / coercion / coercion.acceptance.ts View on Github external
it('coerces parameter in query from nested keys to object', async () => {
    spy = sinon.spy(MyController.prototype, 'getObjectFromQuery');
    await client
      .get('/object-from-query')
      .query({
        'filter[where][id]': 1,
        'filter[where][name]': 'Pen',
        'filter[where][active]': true,
      })
      .expect(200);
    sinon.assert.calledWithExactly(spy, {
      // Notice that numeric and boolean values are converted to strings.
      // This is because all values are encoded as strings on URL queries
      // and we did not specify any schema in @param.query.object() decorator.
      where: {
        id: '1',
        name: 'Pen',
        active: 'true',
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 / packages / rest / src / __tests__ / acceptance / coercion / coercion.acceptance.ts View on Github external
it('coerces parameter in header from string to number', async () => {
    spy = sinon.spy(MyController.prototype, 'createNumberFromHeader');
    await client.get('/create-number-from-header').set({num: 100});
    sinon.assert.calledWithExactly(spy, 100);
  });
github strongloop / loopback-next / packages / rest / src / __tests__ / acceptance / coercion / coercion.acceptance.ts View on Github external
it('coerces parameter in path from string to number', async () => {
    spy = sinon.spy(MyController.prototype, 'createNumberFromPath');
    await client.get('/create-number-from-path/100').expect(200);
    sinon.assert.calledWithExactly(spy, 100);
  });
github strongloop / loopback-next / packages / rest / src / __tests__ / acceptance / coercion / coercion.acceptance.ts View on Github external
it('coerces parameter in query from string to number', async () => {
    spy = sinon.spy(MyController.prototype, 'createNumberFromQuery');
    await client
      .get('/create-number-from-query')
      .query({num: 100})
      .expect(200);
    sinon.assert.calledWithExactly(spy, 100);
  });
github strongloop / loopback-next / examples / log-extension / src / __tests__ / log-spy.ts View on Github external
export function createLogSpy() {
  return sinon.spy(InMemoryLog.prototype, 'add');
}