test(web): add unit tests for nestedInstanceOf

Also rename file `utils.ts` to `nestedInstanceOf.ts`.

Test-bot: skip
This commit is contained in:
Eberhard Beilharz 2025-11-20 16:03:17 +01:00
parent 7ec6f8c523
commit 597e433a0f
No known key found for this signature in database
GPG key ID: E9140597606020D3
4 changed files with 49 additions and 2 deletions

View file

@ -3,7 +3,7 @@ import { InputElementTextStore } from './inputTextStore.js';
import { TextAreaElementTextStore } from './textareaTextStore.js';
import { DesignIFrameElementTextStore } from './designIFrameTextStore.js';
import { ContentEditableElementTextStore } from './contentEditableTextStore.js';
import { nestedInstanceOf } from './utils.js';
import { nestedInstanceOf } from './nestedInstanceOf.js';
export function createTextStoreForElement(e: HTMLElement): AbstractElementTextStore<any> {
// Complex type scoping is implemented here so that kmwutils.ts is not a dependency for test compilations.

View file

@ -4,4 +4,4 @@ export { DesignIFrameElementTextStore } from './designIFrameTextStore.js';
export { InputElementTextStore } from './inputTextStore.js';
export { AbstractElementTextStore } from './abstractElementTextStore.js';
export { TextAreaElementTextStore } from './textareaTextStore.js';
export { nestedInstanceOf } from './utils.js';
export { nestedInstanceOf } from './nestedInstanceOf.js';

View file

@ -0,0 +1,47 @@
/*
* Keyman is copyright (C) SIL Global. MIT License.
*/
import { assert } from 'chai';
import { nestedInstanceOf } from 'keyman/engine/element-text-stores';
describe('nestedInstanceOf', () => {
it('returns false for null input', () => {
assert.strictEqual(nestedInstanceOf(null as any, 'HTMLElement'), false);
});
it('returns true for Window object when className is "Window"', () => {
assert.strictEqual(nestedInstanceOf(window as any, 'Window'), true);
});
it('returns false for Window object when className is not "Window"', () => {
assert.strictEqual(nestedInstanceOf(window as any, 'Document'), false);
});
it('returns true for Document object when className is "Document"', () => {
assert.strictEqual(nestedInstanceOf(document as any, 'Document'), true);
});
it('returns false for Document object when className is not "Document"', () => {
assert.strictEqual(nestedInstanceOf(document as any, 'HTMLElement'), false);
});
it('returns true for HTMLElement when className is "HTMLElement"', () => {
const elem = document.createElement('div');
assert.strictEqual(nestedInstanceOf(elem, 'HTMLElement'), true);
});
it('returns false for HTMLElement when className is "HTMLInputElement"', () => {
const elem = document.createElement('div');
assert.strictEqual(nestedInstanceOf(elem, 'HTMLInputElement'), false);
});
it('returns true for HTMLInputElement when className is "HTMLInputElement"', () => {
const input = document.createElement('input');
assert.strictEqual(nestedInstanceOf(input, 'HTMLInputElement'), true);
});
it('returns false for unknown className', () => {
const elem = document.createElement('div');
assert.strictEqual(nestedInstanceOf(elem, 'NonExistentClass'), false);
});
});