From 4800bf77ca53b93f733c680aa76b6bf3799b89ab Mon Sep 17 00:00:00 2001 From: David Yan Date: Mon, 28 Dec 2015 20:08:54 -0800 Subject: [PATCH] Added tests for svg2js behavior if passed in malformed svg --- test/svg2js/_index.js | 69 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/test/svg2js/_index.js b/test/svg2js/_index.js index b57afd917..8fbf916ab 100644 --- a/test/svg2js/_index.js +++ b/test/svg2js/_index.js @@ -380,4 +380,73 @@ describe('svg2js', function() { }); + describe('malformed svg', function() { + + var filepath = PATH.resolve(__dirname, './test.bad.svg'), + root, + error; + + before(function(done) { + + FS.readFile(filepath, 'utf8', function(err, data) { + if (err) { + throw err; + } + + try { + SVG2JS(data, function(result) { + root = result; + }); + } catch (e) { + error = e; + } + + done(); + }); + + }); + + describe('root', function() { + + it('should have property "error"', function() { + return root.should.have.property('error'); + }); + + }); + + describe('root.error', function() { + + it('should be an instance of String', function() { + return root.error.should.an.instanceOf(String); + }); + + it('should be "Error in parsing: Unmatched closing tag: style"', function() { + return root.error.should.equal('Error in parsing: Unmatched closing tag: style'); + }); + + }); + + describe('thrown error', function() { + + it('should be an instance of Error', function() { + return error.should.be.an.instanceOf(Error); + }); + + it('should stringify to "Error: Unmatched closing tag: style"', function() { + return error.toString().should.equal('Error: Unmatched closing tag: style'); + }); + + it('should roughly match root.error', function() { + var rootErrorParts = root.error.split(':'), + thrownErrorParts = error.toString().split(':'); + + return rootErrorParts.reduce(function(result, value, index) { + return result && value.includes(thrownErrorParts[index]); + }, true).should.be.true(); + }); + + }); + + }); + });