Skip to content

Instantly share code, notes, and snippets.

@bobbyg603
Created April 17, 2023 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobbyg603/4ed5a460726e256e92a9429d0c304faa to your computer and use it in GitHub Desktop.
Save bobbyg603/4ed5a460726e256e92a9429d0c304faa to your computer and use it in GitHub Desktop.
How to Build a Web Component
import { MediumFeedElement } from '../src/feed/medium-feed.js';
import { assert, fixture, html, waitUntil } from '@open-wc/testing';
import { article } from './article';
import sinon from 'sinon';
suite('medium-feed', () => {
const url = '🔗';
const cards = 3;
let stubbedFetch: sinon.SinonStub;
setup(() => {
const response = createFakeResponse(cards);
stubbedFetch = sinon.stub(globalThis, 'fetch');
stubbedFetch.returns(Promise.resolve(response));
});
teardown(() => {
stubbedFetch.restore();
});
test('gets articles from rss feed', async () => {
const el = await fixture(html`<medium-feed .url="${url}"></medium-feed>`) as MediumFeedElement;
await el.updateComplete;
assert.isTrue(stubbedFetch.calledWith(`https://api.rss2json.com/v1/api.json?rss_url=${url}`));
});
function createFakeResponse(cards: number) {
const items = Array.from(Array(cards)).map(() => article);
return new Response(
JSON.stringify({
items
})
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment