/
githubmirror
/
ionic-framework
Обзор
Документация
Войти
/
githubmirror
/
ionic-framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
core/src/utils/test/ready.spec.ts
48 строк
1 KB
Sean Perkins
chore(core): type checking for unit tests (#28529)
17 ноя 2023, 19:47
Не верифицирован
17 ноя 2023, 19:47
4f1b4cd
Код
Авторство
О чём код?
import { componentOnReady } from '../helpers'; describe('componentOnReady()', () => { it('should correctly call callback for a custom element', (done) => { customElements.define( 'hello-world', class extends HTMLElement { constructor() { super(); } } ); const component = document.createElement('hello-world'); componentOnReady(component, (el: HTMLElement) => { expect(el).toBe(component); done(); }); }); it('should correctly call callback for a lazy loaded component', (done) => { const cb = jest.fn((el) => { return new Promise((resolve) => { setTimeout(() => resolve(el), 250); }); }); customElements.define( 'hello-world', class extends HTMLElement { constructor() { super(); } componentOnReady() { return cb(this); } } ); const component = document.createElement('hello-world'); componentOnReady(component, (el: HTMLElement) => { expect(el).toBe(component); expect(cb).toHaveBeenCalledTimes(1); done(); }); }); });