chore: fix types

This commit is contained in:
Thijs Louisse 2022-03-16 00:16:08 +01:00
parent 1b5878678b
commit 938bdbd2dc
6 changed files with 27 additions and 17 deletions

View file

@ -48,7 +48,7 @@ describe('Validator', () => {
it('throws when executing a Validator without a name', async () => {
class MyValidator extends Validator {}
expect(() => {
new MyValidator().execute();
new MyValidator().execute(undefined);
}).to.throw(
'A validator needs to have a name! Please set it via "static get validatorName() { return \'IsCat\'; }"',
);
@ -61,7 +61,10 @@ describe('Validator', () => {
}
}
const vali = new MyValidator({}, { getMessage: 'This is the custom error message' });
const vali = new MyValidator(
{},
{ getMessage: async () => 'This is the custom error message' },
);
const { getMessage } = getProtectedMembers(vali);
await expectThrowsAsync(
@ -76,8 +79,8 @@ describe('Validator', () => {
});
it('receives a config object (optionally) as a second argument on instantiation', async () => {
const vali = new Validator('myParam', { my: 'config' });
expect(vali.config).to.eql({ my: 'config' });
const vali = new Validator('myParam', { fieldName: 'X' });
expect(vali.config).to.eql({ fieldName: 'X' });
});
it('has access to name, type, params, config in getMessage provided by config', () => {
@ -87,7 +90,7 @@ describe('Validator', () => {
return 'MyValidator';
}
}
const vali = new MyValidator('myParam', { my: 'config', getMessage: configSpy });
const vali = new MyValidator('myParam', { fieldName: 'X', getMessage: configSpy });
const { getMessage } = getProtectedMembers(vali);
getMessage();
@ -114,7 +117,7 @@ describe('Validator', () => {
return '';
}
}
const vali = new MyValidator('myParam', { my: 'config' });
const vali = new MyValidator('myParam', { fieldName: 'X' });
const { getMessage } = getProtectedMembers(vali);
getMessage();
@ -137,12 +140,12 @@ describe('Validator', () => {
});
it('fires "config-changed" event on config change', async () => {
const vali = new Validator('foo', { foo: 'bar' });
const vali = new Validator('foo', { fieldName: 'X' });
const cb = sinon.spy(() => {});
if (vali.addEventListener) {
vali.addEventListener('config-changed', cb);
}
vali.config = { bar: 'foo' };
vali.config = { fieldName: 'Y' };
expect(cb.callCount).to.equal(1);
});

View file

@ -46,7 +46,7 @@ describe('Form Validation Integrations', () => {
await fixture(html`
<${elTag}
.validators=${[
new Required(null, { getMessage: () => 'error' }),
new Required(null, { getMessage: async () => 'error' }),
new WarnValidator(null, { getMessage: () => 'warning' }),
new DefaultSuccess(),
]}

View file

@ -5,6 +5,11 @@ import { IsNumber } from '@lion/form-core';
import { formatAmount, formatCurrencyLabel } from './formatters.js';
import { parseAmount } from './parsers.js';
/**
* @typedef {import('@lion/form-core/types/FormatMixinTypes').FormatOptions} FormatOptions
* @typedef {FormatOptions & {locale?:string;currency:string|undefined}} AmountFormatOptions
*/
/**
* `LionInputAmount` is a class for an amount custom form element (`<lion-input-amount>`).
*
@ -87,9 +92,10 @@ export class LionInputAmount extends LocalizeMixin(LionInput) {
if (changedProperties.has('locale') && this.locale !== changedProperties.get('locale')) {
if (this.locale) {
this.formatOptions.locale = this.locale;
/** @type {AmountFormatOptions} */
(this.formatOptions).locale = this.locale;
} else {
delete this.formatOptions.locale;
delete (/** @type {AmountFormatOptions} */ (this.formatOptions).locale);
}
this.__reformat();
}
@ -141,7 +147,8 @@ export class LionInputAmount extends LocalizeMixin(LionInput) {
return;
}
this.formatOptions.currency = currency || undefined;
/** @type {AmountFormatOptions} */
(this.formatOptions).currency = currency || undefined;
if (currency) {
if (!this.__currencyDisplayNodeIsConnected) {
this.appendChild(this.__currencyDisplayNode);

View file

@ -110,7 +110,7 @@ export class IsIBAN extends Validator {
* @param {string} [data.type]
* @param {Object.<string,?>} [data.config]
* @param {string} [data.name]
* @returns {Promise<string|Node>}
* @returns {Promise<string|Element>}
*/
static async getMessage(data) {
await loadTranslations();
@ -153,7 +153,7 @@ export class IsCountryIBAN extends IsIBAN {
* @param {string} [data.type]
* @param {Object.<string,?>} [data.config]
* @param {string} [data.name]
* @returns {Promise<string|Node>}
* @returns {Promise<string|Element>}
*/
static async getMessage(data) {
await loadTranslations();
@ -200,7 +200,7 @@ export class IsNotCountryIBAN extends IsIBAN {
* @param {string} [data.type]
* @param {Object.<string,?>} [data.config]
* @param {string} [data.name]
* @returns {Promise<string|Node>}
* @returns {Promise<string|Element>}
*/
static async getMessage(data) {
await loadTranslations();

View file

@ -2,7 +2,7 @@ import { PhoneUtilManager } from './PhoneUtilManager.js';
/**
* @typedef {import('../types').RegionCode} RegionCode
* @typedef {* & import('awesome-phonenumber').default} PhoneNumber
* @typedef {* & import('@lion/input-tel/lib/awesome-phonenumber-esm').default} PhoneNumber
*/
/**

View file

@ -120,7 +120,7 @@ export function loadDefaultFeedbackMessages() {
/**
* @param {MessageData} data
* @returns {Promise<string|Node>}
* @returns {Promise<string|Element>}
*/
const getLocalizedMessage = async data => {
await forMessagesToBeReady();