libdom
Version:
Lean Browser Library for typical DOM operations
31 lines (27 loc) • 1.32 kB
JavaScript
;
describe(`Encode HTML special characters in String subject into HTML
entity returning an HTML safe String for HTMLElement.innerHTML
operations using xmlEncode(subject:String).`,
() => {
var xmlEncode = global.libdom.xmlEncode;
it(`1. Should not accept non String as first parameter [subject]
and throws an error instead.`,
() => {
expect(() => xmlEncode(99)).toThrow();
expect(() => xmlEncode([99])).toThrow();
expect(() => xmlEncode({ tag: "<h1></h1>" })).toThrow();
expect(() => xmlEncode(undefined)).toThrow();
expect(() => xmlEncode(false)).toThrow();
});
it(`2. Should accept String as first parameter [subject] and returns
the encoded value.`,
() => {
expect(xmlEncode('<h1>Title</h1>')).
toBe('<h1>Title</h1>');
expect(xmlEncode('<a href="/home" title="Home">Home</a>')).
toBe('<a href="/home" title='+
'"Home">Home</a>');
expect(xmlEncode('Just a string!')).
toBe(`Just a string!`);
});
});