awesome-string
Version:
The ultimate JavaScript string library
29 lines (24 loc) • 1.1 kB
JavaScript
import as from '../awesome-string';
import { expect } from 'chai';
import { PRINTABLE_ASCII } from '../const';
describe('escapeHtml', function() {
it('should return the escaped string', function() {
expect(as.escapeHtml('<>&"\'`')).to.be.equal('<>&"'`');
expect(as.escapeHtml('<p>wonderful world</p>')).to.be.equal('<p>wonderful world</p>');
expect(as.escapeHtml(PRINTABLE_ASCII)).to.be.equal(
' !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~');
});
it('should return the escaped string representation of an object', function() {
expect(as.escapeHtml(['<span>'])).to.be.equal('<span>');
expect(as.escapeHtml({
toString: function() {
return '<script>';
}
})).to.be.equal('<script>');
});
it('should return an empty string for null or undefined', function() {
expect(as.escapeHtml()).to.be.equal('');
expect(as.escapeHtml(undefined)).to.be.equal('');
expect(as.escapeHtml(null)).to.be.equal('');
});
});