chore: improve validators instance error message
This commit is contained in:
parent
679d189ec4
commit
7e68ccbddc
2 changed files with 3 additions and 3 deletions
|
|
@ -470,7 +470,7 @@ export const ValidateMixinImplementation = superclass =>
|
||||||
if (!(v instanceof Validator)) {
|
if (!(v instanceof Validator)) {
|
||||||
// throws in constructor are not visible to end user so we do both
|
// throws in constructor are not visible to end user so we do both
|
||||||
const errorType = Array.isArray(v) ? 'array' : typeof v;
|
const errorType = Array.isArray(v) ? 'array' : typeof v;
|
||||||
const errorMessage = `Validators array only accepts class instances of Validator. Type "${errorType}" found.`;
|
const errorMessage = `Validators array only accepts class instances of Validator. Type "${errorType}" found. This may be caused by having multiple installations of @lion/form-core.`;
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(errorMessage, this);
|
console.error(errorMessage, this);
|
||||||
throw new Error(errorMessage);
|
throw new Error(errorMessage);
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ export function runValidateMixinSuite(customConfig) {
|
||||||
const stub = sinon.stub(console, 'error');
|
const stub = sinon.stub(console, 'error');
|
||||||
const el = /** @type {ValidateElement} */ (await fixture(html`<${tag}></${tag}>`));
|
const el = /** @type {ValidateElement} */ (await fixture(html`<${tag}></${tag}>`));
|
||||||
const errorMessage =
|
const errorMessage =
|
||||||
'Validators array only accepts class instances of Validator. Type "array" found.';
|
'Validators array only accepts class instances of Validator. Type "array" found. This may be caused by having multiple installations of @lion/form-core.';
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// @ts-expect-error putting the wrong value on purpose
|
// @ts-expect-error putting the wrong value on purpose
|
||||||
el.validators = [[new Required()]];
|
el.validators = [[new Required()]];
|
||||||
|
|
@ -78,7 +78,7 @@ export function runValidateMixinSuite(customConfig) {
|
||||||
expect(stub.args[0][0]).to.equal(errorMessage);
|
expect(stub.args[0][0]).to.equal(errorMessage);
|
||||||
|
|
||||||
const errorMessage2 =
|
const errorMessage2 =
|
||||||
'Validators array only accepts class instances of Validator. Type "string" found.';
|
'Validators array only accepts class instances of Validator. Type "string" found. This may be caused by having multiple installations of @lion/form-core.';
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// @ts-expect-error because we purposely put a wrong type
|
// @ts-expect-error because we purposely put a wrong type
|
||||||
el.validators = ['required'];
|
el.validators = ['required'];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue