mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-05 00:15:32 +00:00
test(web): add unit tests for nestedInstanceOf
Also rename file `utils.ts` to `nestedInstanceOf.ts`. Test-bot: skip
This commit is contained in:
parent
7ec6f8c523
commit
597e433a0f
4 changed files with 49 additions and 2 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue