-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathrender.spec.js
98 lines (93 loc) · 2.38 KB
/
render.spec.js
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
91
92
93
94
95
96
97
98
import React from 'react';
import { expect } from 'chai';
import {
render,
Mjml,
MjmlHead,
MjmlTitle,
MjmlBody,
MjmlRaw,
MjmlSection,
MjmlHtmlAttribute,
MjmlHtmlAttributes,
MjmlSelector,
MjmlColumn,
MjmlText,
} from '../src';
describe('render()', () => {
it('should render the HTML', () => {
const email = (
<Mjml>
<MjmlHead>
<MjmlTitle>Title</MjmlTitle>
</MjmlHead>
<MjmlBody>
<MjmlRaw>
<p>Paragraph</p>
</MjmlRaw>
</MjmlBody>
</Mjml>
);
const { html } = render(email, { minify: true });
expect(html).to.not.be.undefined;
expect(html).to.contain('<!doctype html>');
expect(html).to.contain('<title>Title</title>');
expect(html).to.contain('<p>Paragraph</p>');
});
it('should throw an error if invalid markup is given', () => {
const email = (
<Mjml>
<MjmlBody>
<div>Ooops!</div>
</MjmlBody>
</Mjml>
);
expect(() => render(email)).to.throw(
"Element div doesn't exist or is not registered",
);
});
it('should not throw an error if soft validation level is passed', () => {
const email = (
<Mjml>
<MjmlBody>
<div>Ooops!</div>
</MjmlBody>
</Mjml>
);
const { errors } = render(email, {
validationLevel: 'soft',
minify: false,
});
expect(errors.length).to.equal(1);
expect(errors[0].message).to.contain(
"Element div doesn't exist or is not registered",
);
});
it('should render html attributes with custom selector', () => {
const email = (
<Mjml>
<MjmlHead>
<MjmlHtmlAttributes>
<MjmlSelector path=".custom div">
<MjmlHtmlAttribute name="data-id">42</MjmlHtmlAttribute>
</MjmlSelector>
</MjmlHtmlAttributes>
</MjmlHead>
<MjmlBody>
<MjmlSection>
<MjmlColumn>
<MjmlText css-class="custom">Hello World!</MjmlText>
</MjmlColumn>
</MjmlSection>
</MjmlBody>
</Mjml>
);
const { html } = render(email, {
validationLevel: 'soft',
minify: false,
});
expect(html).contains(
'<div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#000000;" data-id="42">Hello World!</div>',
);
});
});