-
Notifications
You must be signed in to change notification settings - Fork 960
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow functions to be added as styles in head (#2377)
Allow functions to be added as styles in head
- Loading branch information
Showing
6 changed files
with
85 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('./html-attributes.test') | ||
require('./lazy-head-style.test') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const chai = require('chai') | ||
const spies = require('chai-spies') | ||
const mjml = require('../lib') | ||
|
||
chai.use(spies) | ||
|
||
const { | ||
HeadComponent, | ||
registerComponent, | ||
} = require('../../mjml-core/lib/index') | ||
|
||
const addStyle = chai.spy( | ||
(breakpoint) => ` | ||
@media only screen and (max-width:${breakpoint}) { | ||
h1 { | ||
font-size: 20px; | ||
} | ||
} | ||
`, | ||
) | ||
|
||
class HeadComponentWithFunctionStyle extends HeadComponent { | ||
handler() { | ||
const { add } = this.context | ||
add('style', addStyle) | ||
} | ||
} | ||
HeadComponentWithFunctionStyle.componentName = 'mj-head-component-with-function-style' | ||
HeadComponentWithFunctionStyle.endingTag = true | ||
HeadComponentWithFunctionStyle.allowedAttributes = {} | ||
|
||
|
||
registerComponent(HeadComponentWithFunctionStyle) | ||
|
||
mjml(` | ||
<mjml> | ||
<mj-head> | ||
<mj-head-component-with-function-style /> | ||
<mj-breakpoint width="300px" /> | ||
</mj-head> | ||
<mj-body> | ||
</mj-body> | ||
</mjml> | ||
`) | ||
|
||
chai.expect(addStyle).to.have.been.called.with('300px') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters