From a0f0b810973a75cea48c9010fb03dfc47b8bbad6 Mon Sep 17 00:00:00 2001 From: Meghea Iulian Date: Thu, 2 Nov 2023 07:48:13 +0200 Subject: [PATCH] chore: cleanup --- src/autocomplete/use-overflow.ts | 2 +- test/cosmoz-autocomplete.test.js | 14 +++--- test/cosmoz-listbox.test.js | 45 +++++------------ test/use-autocomplete.test.js | 86 ++++++++++++++++++-------------- test/use-keyboard.test.js | 18 +++---- test/use-listbox.test.js | 8 +-- test/utils.test.js | 4 +- 7 files changed, 83 insertions(+), 94 deletions(-) diff --git a/src/autocomplete/use-overflow.ts b/src/autocomplete/use-overflow.ts index 38746a50..aa151de6 100644 --- a/src/autocomplete/use-overflow.ts +++ b/src/autocomplete/use-overflow.ts @@ -61,6 +61,6 @@ export const useOverflow = ({ useLayoutEffect( () => (enabled ? doRaf() : undefined), - [enabled, width, active, value] + [enabled, width, active, value], ); }; diff --git a/test/cosmoz-autocomplete.test.js b/test/cosmoz-autocomplete.test.js index ad2940b8..34f13739 100644 --- a/test/cosmoz-autocomplete.test.js +++ b/test/cosmoz-autocomplete.test.js @@ -113,12 +113,14 @@ describe('cosmoz-autocomplete', () => { }); it('effects', async () => { - const el = await fixture(html` `); + const el = await fixture( + html` `, + ); el.text = 'asd'; el.value = [source[1]]; diff --git a/test/cosmoz-listbox.test.js b/test/cosmoz-listbox.test.js index be1919dc..f3882873 100644 --- a/test/cosmoz-listbox.test.js +++ b/test/cosmoz-listbox.test.js @@ -8,29 +8,6 @@ const ready = async (el) => { await nextFrame(); }; -// TODO: Remove when https://github.com/lit/lit/pull/3708 is merged -before(() => { - const e = window.onerror; - window.onerror = function (err) { - if ( - err.startsWith('TypeError: this._layout is null') || - err.startsWith( - // eslint-disable-next-line quotes - "TypeError: Cannot read properties of null (reading 'measureChildren')" - ) || - err.startsWith( - // eslint-disable-next-line quotes - "Uncaught TypeError: Cannot read properties of null (reading 'measureChildren')" - ) - ) { - // eslint-disable-next-line no-console - console.warn(`[ignored] ${err}`); - return false; - } - return e(...arguments); - }; -}); - describe('cosmoz-listbox', () => { it('render', async () => { const onSelect = spy(), @@ -41,7 +18,7 @@ describe('cosmoz-listbox', () => { html`` + >`, ); await ready(el); @@ -69,7 +46,7 @@ describe('cosmoz-listbox', () => { .items=${items} .onSelect=${onSelect} .textual=${prop('text')} - >` + >`, ); await ready(el); @@ -82,12 +59,14 @@ describe('cosmoz-listbox', () => { items = Array(10) .fill() .map((_, i) => ({ textProp: `item ${i}` })), - el = await fixture(html``); + el = await fixture( + html``, + ); await ready(el); @@ -103,7 +82,7 @@ describe('cosmoz-listbox', () => { html`` + >`, ); await ready(el); @@ -126,7 +105,7 @@ describe('cosmoz-listbox', () => { html`` + >`, ); await ready(el); diff --git a/test/use-autocomplete.test.js b/test/use-autocomplete.test.js index 60ed61a7..fc87c377 100644 --- a/test/use-autocomplete.test.js +++ b/test/use-autocomplete.test.js @@ -7,7 +7,7 @@ customElements.define( 'use-autocomplete', component((host) => { host.current = useAutocomplete(host); - }) + }), ); describe('use-autocomplete', () => { @@ -28,13 +28,15 @@ describe('use-autocomplete', () => { it('focus', async () => { const onFocus = spy(), source = [{ text: 'Item 1' }, { text: 'Item 2' }], - result = await fixture(html` `); + result = await fixture( + html` `, + ); expect(await result.current.items$).to.be.empty; result.current.onFocus({ currentTarget: { matches: () => true } }); @@ -46,13 +48,15 @@ describe('use-autocomplete', () => { it('edit', async () => { const onText = spy(), source = [{ text: 'Item 1' }, { text: 'Item 2' }], - result = await fixture(html` `); + result = await fixture( + html` `, + ); onText.resetHistory(); result.current.onText({ target: { value: 'ite' } }); await nextFrame(); @@ -63,14 +67,16 @@ describe('use-autocomplete', () => { const onText = spy(), onChange = spy(), source = [{ text: 'Item 1' }, { text: 'Item 2' }], - result = await fixture(html` `); + result = await fixture( + html` `, + ); onText.resetHistory(); result.current.onSelect(source[1]); @@ -82,13 +88,15 @@ describe('use-autocomplete', () => { it('onSelect', async () => { const onSelect = spy(), source = [{ text: 'Item 1' }, { text: 'Item 2' }], - result = await fixture(html` `); + result = await fixture( + html` `, + ); result.current.onSelect(source[1]); await nextFrame(); @@ -99,14 +107,16 @@ describe('use-autocomplete', () => { const onText = spy(), onChange = spy(), source = [{ text: 'Item 1' }, { text: 'Item 2' }], - result = await fixture(html` `); + result = await fixture( + html` `, + ); onText.resetHistory(); result.current.onDeselect(source[0]); await nextFrame(); diff --git a/test/use-keyboard.test.js b/test/use-keyboard.test.js index 23afa4da..d3ece9aa 100644 --- a/test/use-keyboard.test.js +++ b/test/use-keyboard.test.js @@ -34,7 +34,7 @@ describe('use-keyboard', () => { const onDown = spy(); await fixture(html` `); document.dispatchEvent( - new KeyboardEvent('keydown', { key: 'ArrowDown' }) + new KeyboardEvent('keydown', { key: 'ArrowDown' }), ); expect(onDown).to.have.been.calledOnce; }); @@ -54,36 +54,34 @@ describe('use-keyboard', () => { const onUp = spy(), onDown = spy(), onEnter = spy(); - await fixture( - html` - - ` - ); + await fixture(html` + + `); document.dispatchEvent( new KeyboardEvent('keydown', { key: 'Up', ctrlKey: true, altKey: true, - }) + }), ); document.dispatchEvent( new KeyboardEvent('keydown', { key: 'Down', ctrlKey: true, altKey: true, - }) + }), ); document.dispatchEvent( new KeyboardEvent('keydown', { key: 'Enter', ctrlKey: true, altKey: true, - }) + }), ); document.dispatchEvent( new KeyboardEvent('keydown', { key: 'unhandled', - }) + }), ); expect(onUp).not.to.have.been.called; diff --git a/test/use-listbox.test.js b/test/use-listbox.test.js index f3c1b01c..b6ae608e 100644 --- a/test/use-listbox.test.js +++ b/test/use-listbox.test.js @@ -7,7 +7,7 @@ customElements.define( 'use-listbox', component((host) => { host.current = useListbox(host); - }) + }), ); describe('use-listbox', () => { @@ -59,7 +59,7 @@ describe('use-listbox', () => { const items = [0, 1, 2], onSelect = spy(), result = await fixture( - html`` + html``, ); result.current.select(items[1]); expect(onSelect).to.have.been.calledOnceWith(items[1]); @@ -68,7 +68,7 @@ describe('use-listbox', () => { it('enter (no selection)', async () => { const onSelect = spy(); await fixture( - html`` + html``, ); document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter' })); expect(onSelect).to.have.been.calledOnceWith(0); @@ -77,7 +77,7 @@ describe('use-listbox', () => { it('enter', async () => { const onSelect = spy(), result = await fixture( - html`` + html``, ); result.current.highlight(1); await nextFrame(); diff --git a/test/utils.test.js b/test/utils.test.js index d4fedc2a..45a7af4e 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -10,8 +10,8 @@ describe('utils', () => { search( [{ text: 'abc' }, { text: 'bc' }, { text: 'ad' }, {}], 'bc', - strProp('text') - ) + strProp('text'), + ), ).to.deep.equal([{ text: 'bc' }, { text: 'abc' }]); }); });