diff --git a/package.json b/package.json index f7d2685..7bb8ca0 100644 --- a/package.json +++ b/package.json @@ -28,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 41017c0..d035797 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();