Merge pull request #1156 from ing-bank/chore/multiple-installations-error

chore: improve validators instance error message
This commit is contained in:
Joren Broekema 2020-12-28 11:29:24 +01:00 committed by GitHub
commit 642f825db6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View file

@ -470,7 +470,7 @@ export const ValidateMixinImplementation = superclass =>
if (!(v instanceof Validator)) {
// throws in constructor are not visible to end user so we do both
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
console.error(errorMessage, this);
throw new Error(errorMessage);

View file

@ -70,7 +70,7 @@ export function runValidateMixinSuite(customConfig) {
const stub = sinon.stub(console, 'error');
const el = /** @type {ValidateElement} */ (await fixture(html`<${tag}></${tag}>`));
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(() => {
// @ts-expect-error putting the wrong value on purpose
el.validators = [[new Required()]];
@ -78,7 +78,7 @@ export function runValidateMixinSuite(customConfig) {
expect(stub.args[0][0]).to.equal(errorMessage);
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(() => {
// @ts-expect-error because we purposely put a wrong type
el.validators = ['required'];