shoelace/src/components/include/include.test.ts

33 wiersze
1.0 KiB
TypeScript
Czysty Zwykły widok Historia

2021-06-15 13:11:04 +00:00
import { expect, fixture, html, waitUntil } from '@open-wc/testing';
import sinon from 'sinon';
import '../../../dist/shoelace.js';
import type SlInclude from './include';
describe('<sl-include>', () => {
it('should load content and emit sl-load', async () => {
2021-08-10 21:11:07 +00:00
const el = await fixture<SlInclude>(
html` <sl-include src="https://jsonplaceholder.typicode.com/posts/1"></sl-include> `
);
2021-06-15 13:11:04 +00:00
const loadHandler = sinon.spy();
el.addEventListener('sl-load', loadHandler);
await waitUntil(() => loadHandler.calledOnce);
expect(el.innerHTML).to.contain('"id": 1');
expect(loadHandler).to.have.been.calledOnce;
});
it('should emit sl-error when content cannot be loaded', async () => {
2021-09-24 13:18:28 +00:00
const el = await fixture<SlInclude>(
html` <sl-include src="https://jsonplaceholder.typicode.com/not-found"></sl-include> `
);
2021-06-15 13:11:04 +00:00
const loadHandler = sinon.spy();
el.addEventListener('sl-error', loadHandler);
await waitUntil(() => loadHandler.calledOnce);
expect(loadHandler).to.have.been.calledOnce;
});
});