How to use the @loopback/testlab.expect 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 / openapi-v3 / src / __tests__ / integration / controller-spec.integration.ts View on Github external
schema: {
                    $ref: '#/definitions/Todo',
                  },
                },
              },
            },
          },
        })
        async find(): Promise {
          return []; // dummy implementation, it's never called
        }
      }

      const spec = getControllerSpec(MyController);
      const globalSchemas = (spec.components ?? {}).schemas;
      expect(globalSchemas).to.be.undefined();
    });
github strongloop / loopback-next / packages / context / src / __tests__ / unit / invocation-context.unit.ts View on Github external
it('throws error if method does not exist', () => {
    expect(() => invalidInvocationCtx.assertMethodExists()).to.throw(
      'Method MyController.prototype.invalid-method not found',
    );

    expect(() =>
      invalidInvocationCtxForStaticMethod.assertMethodExists(),
    ).to.throw('Method MyController.invalid-static-method not found');
  });
github strongloop / loopback-next / packages / security / src / __tests__ / unit / subject.unit.ts View on Github external
it('adds credential', () => {
    const cred = {usr: 'auser', pass: 'mypass'};
    subject.addCredential(cred);
    expect(subject.credentials).to.containEql(cred);
  });
});
github strongloop / loopback-next / packages / repository / src / __tests__ / unit / repositories / legacy-juggler-bridge.unit.ts View on Github external
it('implements Repository.save() with id', async () => {
    const repo = new DefaultCrudRepository(Note, ds);
    const note1 = await repo.create({title: 't3', content: 'c3'});
    note1.content = 'c4';
    const note = await repo.save(note1);
    const result = await repo.findById(note!.id);
    expect(result.toJSON()).to.eql(note1.toJSON());
  });
github strongloop / loopback-next / packages / repository / src / __tests__ / unit / type / type.unit.ts View on Github external
it('serializes values', () => {
      expect(anyType.serialize('str')).to.eql('str');
      expect(anyType.serialize(1)).to.eql(1);
      expect(anyType.serialize([1, '2'])).to.eql([1, '2']);
      expect(anyType.serialize(null)).null();
      expect(anyType.serialize(undefined)).undefined();
      const date = new Date();
      expect(anyType.serialize(date)).to.eql(date.toJSON());
      const obj = {x: 1};
      expect(anyType.serialize(obj)).to.eql(obj);
      const json = {
        x: 1,
        y: 2,
        toJSON() {
          return {a: json.x + json.y};
        },
      };
      expect(anyType.serialize(json)).to.eql({a: 3});
github strongloop / loopback-next / packages / context / src / __tests__ / unit / context.unit.ts View on Github external
it('returns singleton value', () => {
      let count = 0;
      ctx
        .bind('foo')
        .toDynamicValue(() => count++)
        .inScope(BindingScope.SINGLETON);
      let result = ctx.getSync('foo');
      expect(result).to.equal(0);
      result = ctx.getSync('foo');
      expect(result).to.equal(0);
      const childCtx = new Context(ctx);
      result = childCtx.getSync('foo');
      expect(result).to.equal(0);
    });
github strongloop / loopback-next / packages / repository / src / __tests__ / unit / decorator / model-and-relation.decorator.unit.ts View on Github external
it('adds model metadata with custom name', () => {
    @model({name: 'foo'})
    class Doohickey {
      name: string;
    }

    const meta = MetadataInspector.getClassMetadata(MODEL_KEY, Doohickey);
    expect(meta).to.eql({name: 'foo'});
  });
github strongloop / loopback-next / packages / context / src / __tests__ / integration / inject.integration.ts View on Github external
it('injects as values', async () => {
    class MyControllerWithValues {
      constructor(
        @inject(filterByTag('foo'))
        public values: string[],
      ) {}
    }

    ctx.bind('my-controller').toClass(MyControllerWithValues);
    const inst = await ctx.get('my-controller');
    expect(inst.values).to.eql(['BAR', 'FOO']);
  });
github strongloop / loopback-next / packages / metadata / src / __tests__ / unit / decorator-factory.unit.ts View on Github external
it('clones regexp', () => {
    const val = {
      re: /Ab/,
    };
    const copy = DecoratorFactory.cloneDeep(val);
    expect(copy.re).to.not.exactly(val.re);
    expect(copy).to.be.eql(val);
  });
});
github strongloop / loopback-next / packages / openapi-v3 / src / __tests__ / unit / decorators / param / param-path.decorator.unit.ts View on Github external
function expectSpecToBeEqual(controller: Function, paramSpec: object) {
  const actualSpec = getControllerSpec(controller);
  expect(actualSpec.paths['/greet/{name}']['get'].parameters).to.eql([
    paramSpec,
  ]);
}