1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-17 19:51:42 +00:00

jest-codemods tests/lib

This commit is contained in:
amedora
2019-08-07 14:17:48 +09:00
parent 606be4304d
commit ffb2603485
12 changed files with 92 additions and 104 deletions

View File

@@ -1,46 +1,45 @@
const { escapeHtmlCharacters } = require('browser/lib/utils')
const test = require('ava')
test('escapeHtmlCharacters should return the original string if nothing needed to escape', t => {
test('escapeHtmlCharacters should return the original string if nothing needed to escape', () => {
const input = 'Nothing to be escaped'
const expected = 'Nothing to be escaped'
const actual = escapeHtmlCharacters(input)
t.is(actual, expected)
expect(actual).toBe(expected)
})
test('escapeHtmlCharacters should skip code block if that option is enabled', t => {
test('escapeHtmlCharacters should skip code block if that option is enabled', () => {
const input = ` <no escape>
<escapeMe>`
const expected = ` <no escape>
&lt;escapeMe&gt;`
const actual = escapeHtmlCharacters(input, { detectCodeBlock: true })
t.is(actual, expected)
expect(actual).toBe(expected)
})
test('escapeHtmlCharacters should NOT skip character not in code block but start with 4 spaces', t => {
test('escapeHtmlCharacters should NOT skip character not in code block but start with 4 spaces', () => {
const input = '4 spaces &'
const expected = '4 spaces &amp;'
const actual = escapeHtmlCharacters(input, { detectCodeBlock: true })
t.is(actual, expected)
expect(actual).toBe(expected)
})
test('escapeHtmlCharacters should NOT skip code block if that option is NOT enabled', t => {
test('escapeHtmlCharacters should NOT skip code block if that option is NOT enabled', () => {
const input = ` <no escape>
<escapeMe>`
const expected = ` &lt;no escape&gt;
&lt;escapeMe&gt;`
const actual = escapeHtmlCharacters(input)
t.is(actual, expected)
expect(actual).toBe(expected)
})
test("escapeHtmlCharacters should NOT escape & character if it's a part of an escaped character", t => {
test("escapeHtmlCharacters should NOT escape & character if it's a part of an escaped character", () => {
const input = 'Do not escape &amp; or &quot; but do escape &'
const expected = 'Do not escape &amp; or &quot; but do escape &amp;'
const actual = escapeHtmlCharacters(input)
t.is(actual, expected)
expect(actual).toBe(expected)
})
test('escapeHtmlCharacters should skip char if in code block', t => {
test('escapeHtmlCharacters should skip char if in code block', () => {
const input = `
\`\`\`
<dontescapeme>
@@ -62,12 +61,12 @@ dasdasdasd
\`\`\`
`
const actual = escapeHtmlCharacters(input, { detectCodeBlock: true })
t.is(actual, expected)
expect(actual).toBe(expected)
})
test('escapeHtmlCharacters should return the correct result', t => {
test('escapeHtmlCharacters should return the correct result', () => {
const input = '& < > " \''
const expected = '&amp; &lt; &gt; &quot; &#39;'
const actual = escapeHtmlCharacters(input)
t.is(actual, expected)
expect(actual).toBe(expected)
})