Skip to content

Commit

Permalink
remark-emoticons: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vhf committed Jul 19, 2018
1 parent 2076cf0 commit 8dc60a9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ exports[`emoticons without class 1`] = `
<p>Smiley after another node w/3 spaces: <a href=\\"#foo\\">link</a> <img src=\\"/static/smileys/smile.png\\" alt=\\":)\\"></p>"
`;
exports[`renders case insensitive 1`] = `
"<p><img src=\\"/static/smileys/langue.png\\" alt=\\":p\\"> is same as <img src=\\"/static/smileys/langue.png\\" alt=\\":P\\"></p>
<p><img src=\\"/static/smileys/heureux.png\\" alt=\\":d\\"> is same as <img src=\\"/static/smileys/heureux.png\\" alt=\\":D\\"></p>
<p><img src=\\"/static/smileys/blink.gif\\" alt=\\"o_O\\"> is same as <img alt=\\"o_o\\"> and <img alt=\\"O_O\\"></p>
<p><img src=\\"/static/smileys/magicien.png\\" alt=\\":magicien:\\"> is same as <img src=\\"/static/smileys/magicien.png\\" alt=\\":MAGICIEN:\\"> and as <img src=\\"/static/smileys/magicien.png\\" alt=\\":mAgIcIeN:\\"></p>"
`;
exports[`renders to markdown 1`] = `
"Hello :) Hey :D
Expand Down
29 changes: 14 additions & 15 deletions packages/remark-emoticons/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import dedent from 'dedent'
import unified from 'unified'
import reParse from 'remark-parse'
import stringify from 'rehype-stringify'
import visit from 'unist-util-visit'
import remark2rehype from 'remark-rehype'
import remarkStringify from 'remark-stringify'
import remarkCaption from '../../remark-captions/src'
Expand All @@ -19,7 +20,7 @@ const config = {
'^^': '/static/smileys/hihi.png',
':o': '/static/smileys/huh.png',
':p': '/static/smileys/langue.png',
':magicien:': '/static/smileys/magicien.png',
':magICIen:': '/static/smileys/magicien.png',
':colere2:': '/static/smileys/mechant.png',
':ninja:': '/static/smileys/ninja.png',
'x(': '/static/smileys/pinch.png',
Expand Down Expand Up @@ -115,7 +116,7 @@ test('emoticons without class', () => {
expect(contents).toMatchSnapshot()
})

test('Errors without config', () => {
test('errors without config', () => {
const fail = () => unified()
.use(reParse)
.use(remark2rehype)
Expand Down Expand Up @@ -156,24 +157,22 @@ test('renders to markdown', () => {
expect(recompiled).toBe(contents)
})

test('renders case insensitive', () => {
test('emoticons are case insensitive', () => {
const render = text => unified()
.use(reParse)
.use(plugin, config)
.use(() => (tree) => {
visit(tree, 'emoticon', (node) => {
node.data.hProperties.alt = ''
})
})
.use(remark2rehype)
.use(stringify)
.processSync(text)

delete config.classes

const {contents} = render(dedent`
:p is same as :P
:d is same as :D
o_O is same as o_o and O_O
:magicien: is same as :MAGICIEN: and as :mAgIcIeN:
`)
expect(contents).toMatchSnapshot()
expect(render(`:p`).contents).toBe(render(`:P`).contents)
expect(render(`:d`).contents).toBe(render(`:D`).contents)
expect(render(`:magicien:`).contents).toBe(render(`:MAGICIEN:`).contents)
expect(render(`:magicien:`).contents).toBe(render(`:MagICIEn:`).contents)
expect(render(`:magICIen:`).contents).toBe(render(`:MagICIEn:`).contents)
})
3 changes: 2 additions & 1 deletion packages/remark-emoticons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"rehype-stringify": "^4.0.0",
"remark-parse": "^5.0.0",
"remark-rehype": "^3.0.0",
"unified": "^7.0.0"
"unified": "^7.0.0",
"unist-util-visit": "^1.3.1"
}
}

0 comments on commit 8dc60a9

Please sign in to comment.