Skip to content

Commit

Permalink
test: add tests for focusElement
Browse files Browse the repository at this point in the history
  • Loading branch information
motss committed Sep 17, 2021
1 parent 45ae3ac commit e0c70d5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/tests/helpers/focus-element.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect, fixture, html } from '@open-wc/testing';

import { focusElement } from '../../helpers/focus-element';

describe(focusElement.name, () => {
it('focuses element', async () => {
const el = await fixture<HTMLButtonElement>(html`<button>Focus me</button>`);

const focusedElement = await focusElement(Promise.resolve(el));

expect(document.activeElement).dom.equal(focusedElement);
});

it('focuses element with optional callback', async () => {
const el = await fixture<HTMLButtonElement>(html`<button>Focus me</button>`);

const focusedElement = await new Promise(async (resolve) => {
await focusElement(Promise.resolve(el), (n => {
resolve(n);
}));
});

expect(document.activeElement).dom.equal(focusedElement);
});
});

0 comments on commit e0c70d5

Please sign in to comment.