Skip to content
Permalink
Browse files

Adds test for encodeXML lambda

  • Loading branch information...
davidmerfield committed Aug 29, 2019
1 parent d3c2cf6 commit 7b61262ea93eb6b413cedca4981eb83d778edbe1
Showing with 41 additions and 0 deletions.
  1. +41 −0 app/blog/render/retrieve/tests/encodeXML.js
@@ -0,0 +1,41 @@
describe("encodeXML", function() {
var encodeXML = require("../encodeXML");
var mustache = require("mustache");

global.test.blog();

beforeEach(function() {
this.request = {
protocol: "http",
get: function() {
return "example.com";
}
};
});

it("replaces relative links with absolute URLs", function(done) {
var result;
var locals = {};
var html = '<a href="/foo"></a>';
var template = "{{#encodeXML}}" + html + "{{/encodeXML}}";

encodeXML(this.request, function(err, lambda) {
result = mustache.render(template, { encodeXML: lambda });
expect(result).toEqual('<a href="http://example.com/foo"></a>');
done();
});
});

it("removes invalid characters", function(done) {
var result;
var locals = {};
var html = '& foo &#xFF08;&#x4FBF;&#x5229;';
var template = "{{#encodeXML}}" + html + "{{/encodeXML}}";

encodeXML(this.request, function(err, lambda) {
result = mustache.render(template, { encodeXML: lambda });
expect(result).toEqual('&amp; foo &#xFF08;&#x4FBF;&#x5229;');
done();
});
});
});

0 comments on commit 7b61262

Please sign in to comment.
You can’t perform that action at this time.