Skip to content

Commit 2a6d677

Browse files
committed
tests: start
1 parent e4b7cc2 commit 2a6d677

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

deno.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"imports": {
3+
"@std/assert": "jsr:@std/assert@^1.0.4"
4+
}
5+
}

deno.lock

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/info_test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Feed } from "../src/main.ts";
2+
import { assertEquals } from "@std/assert";
3+
4+
Deno.test("minimal", () => {
5+
const info = {
6+
title: "My Example Feed",
7+
home_page_url: "https://example.org",
8+
feed_url: "https://example.org/feed.json",
9+
};
10+
11+
const feed = new Feed(info);
12+
13+
const version = "https://jsonfeed.org/version/1.1";
14+
const items = [] as const;
15+
const expected = {
16+
version,
17+
...info,
18+
items,
19+
}
20+
21+
assertEquals(feed.toJSON(), JSON.stringify(expected));
22+
})

tests/items_test.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Feed } from "../src/main.ts";
2+
import { assertEquals } from "@std/assert";
3+
4+
Deno.test("three items", () => {
5+
const info = {
6+
title: "My Example Feed",
7+
home_page_url: "https://example.org",
8+
feed_url: "https://example.org/feed.json",
9+
};
10+
11+
const feed = new Feed(info);
12+
13+
const items = [
14+
{
15+
id: "1",
16+
content_html: "<p>Hello, world!</p>",
17+
url: "https://example.org/initial-post",
18+
},
19+
{
20+
id: "2",
21+
content_text: "This is a second item.",
22+
url: "https://example.org/second-item",
23+
},
24+
{
25+
id: "3",
26+
content_html: "<p>This is a third item.</p>",
27+
content_text: "This is a third item.",
28+
url: "https://example.org/third-item",
29+
},
30+
]
31+
32+
feed.add(...items);
33+
34+
const version = "https://jsonfeed.org/version/1.1";
35+
const expected = {
36+
version,
37+
...info,
38+
items,
39+
}
40+
41+
assertEquals(feed.toJSON(), JSON.stringify(expected));
42+
})

0 commit comments

Comments
 (0)