From 563fdcba94b60b62e308d9cfa8d6b03ae7a15234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Vi=E1=BB=87t=20H=C6=B0ng?= Date: Sat, 7 Jul 2018 00:04:11 +0700 Subject: [PATCH] added tests escape html function --- tests/lib/escapeHtmlCharacters-test.js | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/lib/escapeHtmlCharacters-test.js diff --git a/tests/lib/escapeHtmlCharacters-test.js b/tests/lib/escapeHtmlCharacters-test.js new file mode 100644 index 00000000..f13ab297 --- /dev/null +++ b/tests/lib/escapeHtmlCharacters-test.js @@ -0,0 +1,48 @@ +const { escapeHtmlCharacters } = require('browser/lib/utils') +const test = require('ava') + +test('escapeHtmlCharacters should return the original string if nothing needed to escape', t => { + const input = 'Nothing to be escaped' + const expected = 'Nothing to be escaped' + const actual = escapeHtmlCharacters(input) + t.is(actual, expected) +}) + +test('escapeHtmlCharacters should skip code block if that option is enabled', t => { + const input = ` +` + const expected = ` +<escapeMe>` + const actual = escapeHtmlCharacters(input, { detectCodeBlock: true }) + t.is(actual, expected) +}) + +test('escapeHtmlCharacters should NOT skip character not in code block but start with 4 spaces', t => { + const input = '4 spaces &' + const expected = '4 spaces &' + const actual = escapeHtmlCharacters(input, { detectCodeBlock: true }) + t.is(actual, expected) +}) + +test('escapeHtmlCharacters should NOT skip code block if that option is NOT enabled', t => { + const input = ` +` + const expected = ` <no escape> +<escapeMe>` + const actual = escapeHtmlCharacters(input) + t.is(actual, expected) +}) + +test('escapeHtmlCharacters should NOT escape & character if it\'s a part of an escaped character', t => { + const input = 'Do not escape & or " but do escape &' + const expected = 'Do not escape & or " but do escape &' + const actual = escapeHtmlCharacters(input) + t.is(actual, expected) +}) + +test('escapeHtmlCharacters should return the correct result', t => { + const input = '& < > " \'' + const expected = '& < > " '' + const actual = escapeHtmlCharacters(input) + t.is(actual, expected) +})