Skip to content

Commit c2cd8ce

Browse files
committed
test: Fix tests
1 parent 9ce94f0 commit c2cd8ce

3 files changed

Lines changed: 106 additions & 113 deletions

File tree

.jestrc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
},
1313
"collectCoverageFrom": [
1414
"!**/node_modules/**",
15-
"!**/src/demo/**/*.(js|jsx)",
16-
"!**/src/test*/**/*.(js|jsx)",
15+
"!<rootDir>/src/demo/**/*.(js|jsx)",
16+
"!<rootDir>/src/test*/**/*.(js|jsx)",
17+
"!<rootDir>/dist/lit-ntml.js",
1718
"<rootDir>/dist/**/*.(js|jsx)"
1819
],
1920
"verbose": true,

src/test/html-fragment.spec.ts

Lines changed: 56 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { htmlFragment } from '..';
1+
import { htmlFragment as html } from '..';
22

33
const helloWorld = `<h1>Hello, World!</h1>`;
44
const peopleList = [
@@ -8,77 +8,72 @@ const peopleList = [
88
'Cash Black',
99
];
1010

11-
describe('htmlFragment', () => {
12-
const html = htmlFragment;
13-
14-
it(`throws when error happens`, async () => {
15-
try {
16-
const errorContent = async () => { throw new Error('error'); };
17-
await html`${errorContent}`;
18-
} catch (e) {
19-
expect(e).toStrictEqual(new Error('error'));
20-
}
21-
});
22-
23-
it(`renders`, async () => {
24-
const d = await html`${helloWorld}`;
11+
it(`throws when error happens`, async () => {
12+
try {
13+
const errorContent = async () => { throw new Error('error'); };
14+
await html`${errorContent}`;
15+
} catch (e) {
16+
expect(e).toStrictEqual(new Error('error'));
17+
}
18+
});
2519

26-
expect(d).toStrictEqual(
27-
`<h1>Hello, World!</h1>`
28-
);
29-
});
20+
it(`renders`, async () => {
21+
const d = await html`${helloWorld}`;
3022

31-
it(`renders with sync tasks`, async () => {
32-
const syncTask = () => helloWorld;
33-
const syncLiteral = 'John Doe';
34-
const d = await html`<section>${syncTask}<h2>${syncLiteral}</h2></section>`;
23+
expect(d).toStrictEqual(
24+
`<h1>Hello, World!</h1>`
25+
);
26+
});
3527

36-
expect(d).toStrictEqual(
37-
// tslint:disable-next-line: max-line-length
38-
`<section><h1>Hello, World!</h1><h2>John Doe</h2></section>`
39-
);
40-
});
28+
it(`renders with sync tasks`, async () => {
29+
const syncTask = () => helloWorld;
30+
const syncLiteral = 'John Doe';
31+
const d = await html`<section>${syncTask}<h2>${syncLiteral}</h2></section>`;
4132

42-
it(`renders with async tasks`, async () => {
43-
const asyncTask = async () => helloWorld;
44-
const asyncLiteral = Promise.resolve('John Doe');
45-
const d = await html`<section>${asyncTask}<h2>${asyncLiteral}</h2></section>`;
33+
expect(d).toStrictEqual(
34+
// tslint:disable-next-line: max-line-length
35+
`<section><h1>Hello, World!</h1><h2>John Doe</h2></section>`
36+
);
37+
});
4638

47-
expect(d).toStrictEqual(
48-
// tslint:disable-next-line: max-line-length
49-
`<section><h1>Hello, World!</h1><h2>John Doe</h2></section>`
50-
);
51-
});
39+
it(`renders with async tasks`, async () => {
40+
const asyncTask = async () => helloWorld;
41+
const asyncLiteral = Promise.resolve('John Doe');
42+
const d = await html`<section>${asyncTask}<h2>${asyncLiteral}</h2></section>`;
5243

53-
it(`renders with a mixture of sync + async tasks`, async () => {
54-
const asyncTask = async () => helloWorld;
55-
const syncLiteral = await 'John Doe';
56-
const d = await html`<section>${asyncTask}<h2>${syncLiteral}</h2></section>`;
44+
expect(d).toStrictEqual(
45+
// tslint:disable-next-line: max-line-length
46+
`<section><h1>Hello, World!</h1><h2>John Doe</h2></section>`
47+
);
48+
});
5749

58-
expect(d).toStrictEqual(
59-
// tslint:disable-next-line: max-line-length
60-
`<section><h1>Hello, World!</h1><h2>John Doe</h2></section>`
61-
);
62-
});
50+
it(`renders with a mixture of sync + async tasks`, async () => {
51+
const asyncTask = async () => helloWorld;
52+
const syncLiteral = await 'John Doe';
53+
const d = await html`<section>${asyncTask}<h2>${syncLiteral}</h2></section>`;
6354

64-
it(`renders a list of sync tasks`, async () => {
65-
const d = await html`${helloWorld}<ul>${peopleList.map(n => `<li>${n}</li>`)}</ul>`;
55+
expect(d).toStrictEqual(
56+
// tslint:disable-next-line: max-line-length
57+
`<section><h1>Hello, World!</h1><h2>John Doe</h2></section>`
58+
);
59+
});
6660

67-
expect(d).toStrictEqual(
68-
// tslint:disable-next-line: max-line-length
69-
`<h1>Hello, World!</h1><ul><li>John Doe</li><li>Michael CEO</li><li>Vict Fisherman</li><li>Cash Black</li></ul>`
70-
);
71-
});
61+
it(`renders a list of sync tasks`, async () => {
62+
const d = await html`${helloWorld}<ul>${peopleList.map(n => `<li>${n}</li>`)}</ul>`;
7263

73-
it(`renders external style`, async () => {
64+
expect(d).toStrictEqual(
7465
// tslint:disable-next-line: max-line-length
75-
const asyncExternalStyleTask = async () => html/* css */`body { margin: 0; padding: 0; box-sizing: border-box; }`;
76-
const d = await html`<style>${asyncExternalStyleTask}</style>${helloWorld}`;
66+
`<h1>Hello, World!</h1><ul><li>John Doe</li><li>Michael CEO</li><li>Vict Fisherman</li><li>Cash Black</li></ul>`
67+
);
68+
});
7769

78-
expect(d).toStrictEqual(
79-
// tslint:disable-next-line: max-line-length
80-
`<style>body { margin: 0; padding: 0; box-sizing: border-box; }</style><h1>Hello, World!</h1>`
81-
);
82-
});
70+
it(`renders external style`, async () => {
71+
// tslint:disable-next-line: max-line-length
72+
const asyncExternalStyleTask = async () => html/* css */`body { margin: 0; padding: 0; box-sizing: border-box; }`;
73+
const d = await html`<style>${asyncExternalStyleTask}</style>${helloWorld}`;
8374

75+
expect(d).toStrictEqual(
76+
// tslint:disable-next-line: max-line-length
77+
`<style>body { margin: 0; padding: 0; box-sizing: border-box; }</style><h1>Hello, World!</h1>`
78+
);
8479
});

src/test/html.spec.ts

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,61 @@ const peopleList = [
88
'Cash Black',
99
];
1010

11-
describe('html', () => {
12-
it(`throws when error happens`, async () => {
13-
try {
14-
const errorContent = async () => { throw new Error('error'); };
15-
await html`${errorContent}`;
16-
} catch (e) {
17-
expect(e).toStrictEqual(new Error('error'));
18-
}
19-
});
20-
21-
it(`renders`, async () => {
22-
const d = await html`${helloWorld}`;
11+
it(`throws when error happens`, async () => {
12+
try {
13+
const errorContent = async () => { throw new Error('error'); };
14+
await html`${errorContent}`;
15+
} catch (e) {
16+
expect(e).toStrictEqual(new Error('error'));
17+
}
18+
});
2319

24-
expect(d).toStrictEqual(
25-
`<!DOCTYPE html><html><head></head><body><h1>Hello, World!</h1></body></html>`
26-
);
27-
});
20+
it(`renders`, async () => {
21+
const d = await html`${helloWorld}`;
2822

29-
it(`renders with sync tasks`, async () => {
30-
const syncTask = () => helloWorld;
31-
const syncLiteral = 'John Doe';
32-
const d = await html`<section>${syncTask}<h2>${syncLiteral}</h2></section>`;
23+
expect(d).toStrictEqual(
24+
`<!DOCTYPE html><html><head></head><body><h1>Hello, World!</h1></body></html>`
25+
);
26+
});
3327

34-
expect(d).toStrictEqual(
35-
// tslint:disable-next-line: max-line-length
36-
`<!DOCTYPE html><html><head></head><body><section><h1>Hello, World!</h1><h2>John Doe</h2></section></body></html>`
37-
);
38-
});
28+
it(`renders with sync tasks`, async () => {
29+
const syncTask = () => helloWorld;
30+
const syncLiteral = 'John Doe';
31+
const d = await html`<section>${syncTask}<h2>${syncLiteral}</h2></section>`;
3932

40-
it(`renders with async tasks`, async () => {
41-
const asyncTask = async () => helloWorld;
42-
const asyncLiteral = Promise.resolve('John Doe');
43-
const d = await html`<section>${asyncTask}<h2>${asyncLiteral}</h2></section>`;
33+
expect(d).toStrictEqual(
34+
// tslint:disable-next-line: max-line-length
35+
`<!DOCTYPE html><html><head></head><body><section><h1>Hello, World!</h1><h2>John Doe</h2></section></body></html>`
36+
);
37+
});
4438

45-
expect(d).toStrictEqual(
46-
// tslint:disable-next-line: max-line-length
47-
`<!DOCTYPE html><html><head></head><body><section><h1>Hello, World!</h1><h2>John Doe</h2></section></body></html>`
48-
);
49-
});
39+
it(`renders with async tasks`, async () => {
40+
const asyncTask = async () => helloWorld;
41+
const asyncLiteral = Promise.resolve('John Doe');
42+
const d = await html`<section>${asyncTask}<h2>${asyncLiteral}</h2></section>`;
5043

51-
it(`renders with a mixture of sync + async tasks`, async () => {
52-
const asyncTask = async () => helloWorld;
53-
const syncLiteral = await 'John Doe';
54-
const d = await html`<section>${asyncTask}<h2>${syncLiteral}</h2></section>`;
44+
expect(d).toStrictEqual(
45+
// tslint:disable-next-line: max-line-length
46+
`<!DOCTYPE html><html><head></head><body><section><h1>Hello, World!</h1><h2>John Doe</h2></section></body></html>`
47+
);
48+
});
5549

56-
expect(d).toStrictEqual(
57-
// tslint:disable-next-line: max-line-length
58-
`<!DOCTYPE html><html><head></head><body><section><h1>Hello, World!</h1><h2>John Doe</h2></section></body></html>`
59-
);
60-
});
50+
it(`renders with a mixture of sync + async tasks`, async () => {
51+
const asyncTask = async () => helloWorld;
52+
const syncLiteral = await 'John Doe';
53+
const d = await html`<section>${asyncTask}<h2>${syncLiteral}</h2></section>`;
6154

62-
it(`renders a list of sync tasks`, async () => {
63-
const d = await html`${helloWorld}<ul>${peopleList.map(n => `<li>${n}</li>`)}</ul>`;
55+
expect(d).toStrictEqual(
56+
// tslint:disable-next-line: max-line-length
57+
`<!DOCTYPE html><html><head></head><body><section><h1>Hello, World!</h1><h2>John Doe</h2></section></body></html>`
58+
);
59+
});
6460

65-
expect(d).toStrictEqual(
66-
// tslint:disable-next-line: max-line-length
67-
`<!DOCTYPE html><html><head></head><body><h1>Hello, World!</h1><ul><li>John Doe</li><li>Michael CEO</li><li>Vict Fisherman</li><li>Cash Black</li></ul></body></html>`
68-
);
69-
});
61+
it(`renders a list of sync tasks`, async () => {
62+
const d = await html`${helloWorld}<ul>${peopleList.map(n => `<li>${n}</li>`)}</ul>`;
7063

64+
expect(d).toStrictEqual(
65+
// tslint:disable-next-line: max-line-length
66+
`<!DOCTYPE html><html><head></head><body><h1>Hello, World!</h1><ul><li>John Doe</li><li>Michael CEO</li><li>Vict Fisherman</li><li>Cash Black</li></ul></body></html>`
67+
);
7168
});

0 commit comments

Comments
 (0)