Skip to content

Commit

Permalink
Added tests for svg2js behavior if passed in malformed svg
Browse files Browse the repository at this point in the history
  • Loading branch information
yandavid committed Dec 29, 2015
1 parent 5c3cb26 commit 4800bf7
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/svg2js/_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

});

});

});

0 comments on commit 4800bf7

Please sign in to comment.