Skip to content

Commit 6dfc0d7

Browse files
author
Maxime Brazeilles
committed
[FIX] Move into async func
1 parent 056c8b3 commit 6dfc0d7

File tree

2 files changed

+79
-70
lines changed

2 files changed

+79
-70
lines changed

packages/mjml/test/html-attributes.test.js

+43-37
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const { load } = require('cheerio')
33
const { sortBy } = require('lodash')
44
const mjml = require('../lib')
55

6-
const input = `
6+
async function run() {
7+
const input = `
78
<mjml>
89
<mj-head>
910
<mj-html-attributes>
@@ -35,44 +36,49 @@ const input = `
3536
</mjml>
3637
`
3738

38-
const { html } = mjml(input)
39-
const $ = load(html)
39+
const { html } = await mjml(input)
40+
const $ = load(html)
4041

41-
// should put the attributes at the right place
42-
chai
43-
.expect(
44-
$('.text div')
45-
.map(function getAttr() {
46-
return $(this).attr('data-id')
47-
})
48-
.get(),
49-
'Custom attributes added on texts',
50-
)
51-
.to.eql(['42', '42'])
42+
// should put the attributes at the right place
43+
chai
44+
.expect(
45+
$('.text div')
46+
.map(function getAttr() {
47+
return $(this).attr('data-id')
48+
})
49+
.get(),
50+
'Custom attributes added on texts',
51+
)
52+
.to.eql(['42', '42'])
5253

53-
chai
54-
.expect(
55-
$('.image td')
56-
.map(function getAttr() {
57-
return $(this).attr('data-name')
58-
})
59-
.get(),
60-
'Custom attributes added on image',
61-
)
62-
.to.eql(['43'])
54+
chai
55+
.expect(
56+
$('.image td')
57+
.map(function getAttr() {
58+
return $(this).attr('data-name')
59+
})
60+
.get(),
61+
'Custom attributes added on image',
62+
)
63+
.to.eql(['43'])
6364

64-
// should not alter templating syntax, or move the content that is outside any tag (mj-raws)
65-
const expected = [
66-
'{ if item < 5 }',
67-
'class="section"',
68-
'{ if item > 10 }',
69-
'class="text"',
70-
'{ item }',
71-
'{ end if }',
72-
'{ item + 1 }',
73-
]
74-
const indexes = expected.map((str) => html.indexOf(str))
65+
// should not alter templating syntax, or move the content that is outside any tag (mj-raws)
66+
const expected = [
67+
'{ if item < 5 }',
68+
'class="section"',
69+
'{ if item > 10 }',
70+
'class="text"',
71+
'{ item }',
72+
'{ end if }',
73+
'{ item + 1 }',
74+
]
75+
const indexes = expected.map((str) => html.indexOf(str))
7576

76-
chai.expect(indexes, 'Templating syntax unaltered').to.not.include(-1)
77+
chai.expect(indexes, 'Templating syntax unaltered').to.not.include(-1)
7778

78-
chai.expect(sortBy(indexes), 'Mj-raws kept same positions').to.deep.eql(indexes)
79+
chai
80+
.expect(sortBy(indexes), 'Mj-raws kept same positions')
81+
.to.deep.eql(indexes)
82+
}
83+
84+
run()
+36-33
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,49 @@
11
const chai = require('chai')
22
const spies = require('chai-spies')
33
const mjml = require('../lib')
4-
5-
chai.use(spies)
6-
74
const {
85
HeadComponent,
96
registerComponent,
107
} = require('../../mjml-core/lib/index')
118

12-
const addStyle = chai.spy(
13-
(breakpoint) => `
14-
@media only screen and (max-width:${breakpoint}) {
15-
h1 {
16-
font-size: 20px;
9+
async function run() {
10+
chai.use(spies)
11+
12+
const addStyle = chai.spy(
13+
(breakpoint) => `
14+
@media only screen and (max-width:${breakpoint}) {
15+
h1 {
16+
font-size: 20px;
17+
}
1718
}
18-
}
19-
`,
20-
)
19+
`,
20+
)
2121

22-
class HeadComponentWithFunctionStyle extends HeadComponent {
23-
handler() {
24-
const { add } = this.context
25-
add('style', addStyle)
22+
class HeadComponentWithFunctionStyle extends HeadComponent {
23+
handler() {
24+
const { add } = this.context
25+
add('style', addStyle)
26+
}
2627
}
28+
HeadComponentWithFunctionStyle.componentName =
29+
'mj-head-component-with-function-style'
30+
HeadComponentWithFunctionStyle.endingTag = true
31+
HeadComponentWithFunctionStyle.allowedAttributes = {}
32+
33+
registerComponent(HeadComponentWithFunctionStyle)
34+
35+
mjml(`
36+
<mjml>
37+
<mj-head>
38+
<mj-head-component-with-function-style />
39+
<mj-breakpoint width="300px" />
40+
</mj-head>
41+
<mj-body>
42+
</mj-body>
43+
</mjml>
44+
`)
45+
46+
chai.expect(addStyle).to.have.been.called.with('300px')
2747
}
28-
HeadComponentWithFunctionStyle.componentName = 'mj-head-component-with-function-style'
29-
HeadComponentWithFunctionStyle.endingTag = true
30-
HeadComponentWithFunctionStyle.allowedAttributes = {}
31-
32-
33-
registerComponent(HeadComponentWithFunctionStyle)
34-
35-
mjml(`
36-
<mjml>
37-
<mj-head>
38-
<mj-head-component-with-function-style />
39-
<mj-breakpoint width="300px" />
40-
</mj-head>
41-
<mj-body>
42-
</mj-body>
43-
</mjml>
44-
`)
4548

46-
chai.expect(addStyle).to.have.been.called.with('300px')
49+
run()

0 commit comments

Comments
 (0)