Files
ionic-framework/core/src/utils/test/ready.spec.ts
2022-04-04 11:12:53 -04:00

49 lines
1.1 KiB
TypeScript

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) => {
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) => {
expect(el).toBe(component);
expect(cb).toHaveBeenCalledTimes(1);
done();
});
});
});