-
Notifications
You must be signed in to change notification settings - Fork 254
/
image.node.tests.tsx
90 lines (81 loc) · 2.7 KB
/
image.node.tests.tsx
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
84
85
86
87
88
89
90
/* eslint-disable @typescript-eslint/ban-ts-comment */
/**
* @jest-environment node
*/
import TestRenderer from "react-test-renderer";
import Image from "../image";
// Mock only useConnect in the 'frontity' module
jest.mock("frontity", () => ({
// @ts-ignore
...jest.requireActual("frontity"),
useConnect: () => ({
state: {
frontity: {
mode: "html",
},
},
}),
}));
describe("Image", () => {
test('It\'s a normal image if loading === "eager"', () => {
const loading: "lazy" | "eager" = "eager";
const props = {
alt: "Some fake alt text",
src: "https://fake-src.com/fake-image.jpg",
srcSet:
"https://fake-src.com/fake-image.jpg?w=300 300w, https://fake-src.com/fake-image.jpg?w=150 150w",
className: "fake-class-name",
loading,
};
const image = TestRenderer.create(<Image {...props} />).toJSON();
expect(image).toMatchInlineSnapshot(`
<img
alt="Some fake alt text"
className="frontity-lazy-image fake-class-name"
loading="eager"
src="https://fake-src.com/fake-image.jpg"
srcSet="https://fake-src.com/fake-image.jpg?w=300 300w, https://fake-src.com/fake-image.jpg?w=150 150w"
/>
`);
});
test("works on server (without height)", () => {
const props = {
alt: "Some fake alt text",
src: "https://fake-src.com/fake-image.jpg",
srcSet:
"https://fake-src.com/fake-image.jpg?w=300 300w, https://fake-src.com/fake-image.jpg?w=150 150w",
className: "fake-class-name",
};
const image = TestRenderer.create(<Image {...props} />).toJSON();
expect(image).toMatchInlineSnapshot(`
<img
alt="Some fake alt text"
className="frontity-lazy-image fake-class-name"
loading="lazy"
src="https://fake-src.com/fake-image.jpg"
srcSet="https://fake-src.com/fake-image.jpg?w=300 300w, https://fake-src.com/fake-image.jpg?w=150 150w"
/>
`);
});
test("works on server (with height)", () => {
const props = {
alt: "Some fake alt text",
src: "https://fake-src.com/fake-image.jpg",
srcSet:
"https://fake-src.com/fake-image.jpg?w=300 300w, https://fake-src.com/fake-image.jpg?w=150 150w",
className: "fake-class-name",
height: 300,
};
const image = TestRenderer.create(<Image {...props} />).toJSON();
expect(image).toMatchInlineSnapshot(`
<img
alt="Some fake alt text"
className="frontity-lazy-image fake-class-name"
height={300}
loading="lazy"
src="https://fake-src.com/fake-image.jpg"
srcSet="https://fake-src.com/fake-image.jpg?w=300 300w, https://fake-src.com/fake-image.jpg?w=150 150w"
/>
`);
});
});