-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-feed.test.js
More file actions
83 lines (71 loc) · 1.99 KB
/
dev-feed.test.js
File metadata and controls
83 lines (71 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { html, fixture, expect } from '@open-wc/testing';
import { stub } from 'sinon';
import './dev-feed.js';
describe('DevFeed', function() {
it('by default sorts by popularity', async () => {
const el = await fixture(html`
<dev-feed></dev-feed>
`);
expect(el.sort).to.equal('popularity');
});
it('shows an empty list initially', async () => {
const el = await fixture(html`
<dev-feed></dev-feed>
`);
expect(el).shadowDom.to.equal(`
<div hidden></div>
<ul id="posts"></ul>
`);
});
describe('with username property', function() {
const username = 'test';
const endpoint = `https://dev.to/api/articles?username=${username}`;
let fetchStub;
let el;
beforeEach(async function() {
fetchStub = stub(window, 'fetch');
fetchStub.returns(Promise.resolve(new Response(JSON.stringify([
{
cover_image: 'cover_image',
description: 'description',
positive_reactions_count: 100,
published_at: 'published_at',
tag_list: ['tag'],
title: 'title',
url: 'url',
user: {
name: 'user.name',
profile_image_90: 'user.profile_image_90',
username: 'user.username',
},
},
]), {
status: 200,
headers: { 'Content-type': 'application/json' },
})));
el = await fixture(html`
<dev-feed username="${username}"></dev-feed>
`);
await new Promise(r => setTimeout(r, 1000));
});
afterEach(function() {
fetchStub.restore();
el.remove();
el = undefined;
});
it('should set the apiEndpoint property', function() {
expect(`${el.apiEndpoint}`).to.equal(endpoint);
});
it('should display the fetched article', async function() {
expect(el).shadowDom.to.equal(`
<div hidden></div>
<ul id="posts">
<li>
<dev-article>
</dev-article>
</li>
</ul>
`);
});
});
});