update dependencies, cleanup, refine (#642)

* update dependencies, cleanup, refine

fixes #637

* update CI command to verify
This commit is contained in:
Jason O'Neill
2022-01-06 05:44:13 -08:00
committed by GitHub
parent 46f05224ab
commit ca346ccbb2
18 changed files with 5108 additions and 6710 deletions

View File

@@ -4,11 +4,37 @@ import sinon from 'sinon';
import '../../../dist/shoelace.js';
import type SlInclude from './include';
const stubbedFetchResponse: Response = {
headers: new Headers(),
ok: true,
redirected: false,
status: 200,
statusText: 'OK',
type: 'default',
url: '',
json: () => Promise.resolve({}),
text: () => Promise.resolve(''),
blob: sinon.fake(),
arrayBuffer: sinon.fake(),
formData: sinon.fake(),
bodyUsed: false,
body: null,
clone: sinon.fake()
};
describe('<sl-include>', () => {
afterEach(() => {
sinon.verifyAndRestore();
});
it('should load content and emit sl-load', async () => {
const el = await fixture<SlInclude>(
html` <sl-include src="https://jsonplaceholder.typicode.com/posts/1"></sl-include> `
);
sinon.stub(window, 'fetch').resolves({
...stubbedFetchResponse,
ok: true,
status: 200,
text: () => Promise.resolve('"id": 1')
});
const el = await fixture<SlInclude>(html` <sl-include src="/found"></sl-include> `);
const loadHandler = sinon.spy();
el.addEventListener('sl-load', loadHandler);
@@ -19,9 +45,13 @@ describe('<sl-include>', () => {
});
it('should emit sl-error when content cannot be loaded', async () => {
const el = await fixture<SlInclude>(
html` <sl-include src="https://jsonplaceholder.typicode.com/not-found"></sl-include> `
);
sinon.stub(window, 'fetch').resolves({
...stubbedFetchResponse,
ok: false,
status: 404,
text: () => Promise.resolve('{}')
});
const el = await fixture<SlInclude>(html` <sl-include src="/not-found"></sl-include> `);
const loadHandler = sinon.spy();
el.addEventListener('sl-error', loadHandler);