From cb1f87ed98fa311834ddbbd94b77e3ec4209921e Mon Sep 17 00:00:00 2001 From: Eric Vantillard Date: Tue, 28 Jan 2014 10:10:14 +0100 Subject: [PATCH] Unit test for issue #25. Should be fixed after pull request https://github.com/dylang/node-xml/pull/12 --- package.json | 9 ++++++--- test/rss.test.js | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 5b83d3d..d6a3245 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rss", - "version": "0.3.0", + "version": "0.3.1", "description": "RSS feed generator. A really simple API to add RSS feeds to any project.", "homepage": "http://github.com/dylang/node-rss", "author": "Dylan Greene ", @@ -11,7 +11,8 @@ "Victor Jonsson", "Danny Graham", "Patrick Garman ", - "Fred Morstatter" + "Fred Morstatter", + "Eric Vantillard " ], "repository": { "type": "git", @@ -27,7 +28,9 @@ }, "devDependencies": { "chai": "~1.8.1", - "mocha": "~1.17.0" + "mocha": "~1.17.0", + "xml2js": "~0.4.1", + "q": "~1.0.0" }, "main": "lib/rss.js", "scripts": { diff --git a/test/rss.test.js b/test/rss.test.js index 41b801e..fa41ca9 100644 --- a/test/rss.test.js +++ b/test/rss.test.js @@ -4,6 +4,8 @@ var RSS = require('../lib/rss'); var expect = require('chai').expect; +var xml2js = require('xml2js'); +var Q = require('q'); describe('rss module', function(done) { @@ -15,7 +17,7 @@ describe('rss module', function(done) { done(); }); - it('should work with an easy test', function(done) { + var simpleFeed = function() { var feed = new RSS({ title: 'title', description: 'description', @@ -68,7 +70,23 @@ describe('rss module', function(done) { author: 'Guest Author', date: 'May 28, 2012 04:00:00 GMT' }); + return feed; + } + it('should work with indentation', function(done) { + var feed = simpleFeed(); + var xml = feed.xml(true); + var parseString = Q.nbind(xml2js.parseString,xml2js); + + var feedToXml = parseString(feed.xml()); + var feedToXmlIndent = parseString(feed.xml(true)); + Q.all([feedToXml,feedToXmlIndent]).spread(function (xml,xmlIndent){ + expect(JSON.stringify(xml)).to.equal(JSON.stringify(xmlIndent)); + }).done(done()); + }); + + it('should work with an easy test', function(done) { + var feed = simpleFeed(); var expectedResult = '\n<![CDATA[title]]>http://example.comhttp://example.com/icon.pngtitlehttp://example.comExample Generator' + new Date().toUTCString() +'Sun, 20 May 2012 04:00:00 GMThttp://example.com/rss/docs.html60<![CDATA[item 1]]>http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT<![CDATA[item 2]]>http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT<![CDATA[item 3]]>http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT<![CDATA[item 4 & html test with <strong>]]>html]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT<![CDATA[item 5 & test for categories]]>http://example.com/article5http://example.com/article5Mon, 28 May 2012 04:00:00 GMT'; var result = feed.xml();