@opra/testing
Version:
Opra testing package
27 lines (26 loc) • 895 B
JavaScript
import '../expect-extend/index.js';
import { omitNullish } from '@jsopen/objects';
import {} from '@opra/common';
import { expect } from 'expect';
import { ApiExpectBase } from './api-expect-base.js';
export class ApiExpectError extends ApiExpectBase {
toMatch(expected) {
try {
if (typeof expected === 'string')
expected = { message: expected };
else if (expected instanceof RegExp) {
expected = {
message: expect.stringMatching(expected),
};
}
else
expected = omitNullish(expected);
this._expect(this.response.body.errors).toEqual(expect.arrayContaining([expect.objectContaining(expected)]));
}
catch (e) {
Error.captureStackTrace(e, this.toMatch);
throw e;
}
return this;
}
}