How to use the @loopback/testlab.expect.throws 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__ / unit / decorators / param / param.decorator.unit.ts View on Github external
it('reports error if an array parameter type is not Array', () => {
      expect.throws(
        () => {
          // eslint-disable-next-line @typescript-eslint/no-unused-vars
          class MyController {
            @get('/greet')
            greet(
              @param.array('names', 'query', {type: 'string'}) names: string,
            ) {}
          }
        },
        Error,
        `The parameter type is set to 'array' but the JavaScript type is String`,
      );
    });
github strongloop / loopback-next / packages / repository / src / __tests__ / unit / decorator / model-and-relation.decorator.unit.ts View on Github external
it('throws when @property.array is used on a non-array property', () => {
        expect.throws(
          () => {
            // eslint-disable-next-line @typescript-eslint/no-unused-vars
            class Oops {
              @property.array(Product)
              product: Product;
            }
          },
          Error,
          property.ERR_PROP_NOT_ARRAY,
        );
      });
    });
github strongloop / loopback-next / packages / openapi-v3 / src / __tests__ / unit / json-to-schema.unit.ts View on Github external
it('errors if type is an array and items is missing', () => {
    expect.throws(
      () => {
        jsonToSchemaObject({type: 'array'});
      },
      Error,
      '"items" property must be present if "type" is an array',
    );
  });
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / rest.application / rest.application.unit.ts View on Github external
it('when attempting to bind an array of servers', () => {
      const app = new RestApplication();
      expect.throws(
        () => {
          app.servers([RestServer, RestServer]);
        },
        Error,
        ERR_NO_MULTI_SERVER,
      );
    });