import 'mocha'; import * as assert from 'assert'; import { makeEndTag, makeStartTag, encodeHtml, decodeHtml, encodeLink, } from './../src/funcs-html'; describe('html module', function () { describe('makeStartTag()', function () { it('should make proper html start tags', function () { var act = makeStartTag('a'); assert.equal(act, ''); act = makeStartTag(''); assert.equal(act, ''); act = makeStartTag('br'); assert.equal(act, '
'); act = makeStartTag('img', [{ key: 'src', value: 'http://' }]); assert.equal(act, ''); var attrs = [ { key: 'class', value: ' cl1 cl2' }, { key: 'style', value: 'color:#333' }, ]; act = makeStartTag('p', attrs); assert.equal(act, '

'); assert.equal(makeStartTag('p', [{ key: 'checked' }]), '

'); }); }); describe('makeEndTag()', function () { it('should make proper html end tags', function () { var act = makeEndTag('a'); assert.equal(act, ''); act = makeEndTag(); assert.equal(act, ''); }); }); describe('encodeHtml()', function () { it('should encode < > & " \' / characters', function () { var act = encodeHtml('hello"my&friend&here()', false); assert.equal( act, 'hello"my<lovely'/>&amp;friend&here()' ); var act = encodeHtml('hello"my&friend&here()'); assert.equal( act, 'hello"my<lovely'/>&friend&here()' ); }); }); describe('decodeHtml()', function () { it('should decode html', function () { var act = decodeHtml( 'hello"my<lovely'/>&friend&here' ); assert.equal(act, 'hello"my&friend&here'); }); }); describe('encodeLink()', function () { it('should encode link', function () { var act = encodeLink('http://www.yahoo.com/?a=b&c=<>()"\''); assert.equal( act, 'http://www.yahoo.com/?a=b&c=<>()"'' ); }); }); });