diff --git a/lib/import/BpmnTreeWalker.js b/lib/import/BpmnTreeWalker.js index 59784a7f..915f19c3 100644 --- a/lib/import/BpmnTreeWalker.js +++ b/lib/import/BpmnTreeWalker.js @@ -112,6 +112,10 @@ function BpmnTraverser(handler) { var rootElement = diagram.plane.bpmnElement; + if (!rootElement) { + throw new Error('no rootElement referenced in BPMNPlane <' + diagram.plane.id + '>'); + } + if (is(rootElement, 'bpmn:Process')) { handleProcess(rootElement); } else diff --git a/test/fixtures/bpmn/error/di-no-bpmn-element.bpmn b/test/fixtures/bpmn/error/di-plane-no-bpmn-element.bpmn similarity index 58% rename from test/fixtures/bpmn/error/di-no-bpmn-element.bpmn rename to test/fixtures/bpmn/error/di-plane-no-bpmn-element.bpmn index d01ef0c8..5cc4e6d1 100644 --- a/test/fixtures/bpmn/error/di-no-bpmn-element.bpmn +++ b/test/fixtures/bpmn/error/di-plane-no-bpmn-element.bpmn @@ -1,13 +1,10 @@ - + + - - - - - + \ No newline at end of file diff --git a/test/spec/browser/ViewerSpec.js b/test/spec/browser/ViewerSpec.js index 25e3e5d0..e1d26721 100644 --- a/test/spec/browser/ViewerSpec.js +++ b/test/spec/browser/ViewerSpec.js @@ -43,7 +43,7 @@ describe('Viewer', function() { describe('error handling', function() { - it('should handle errors', function(done) { + it('should handle non-bpmn input', function(done) { var xml = 'invalid stuff'; @@ -57,6 +57,22 @@ describe('Viewer', function() { }); }); + + it('should handle invalid BPMNPlane#bpmnElement', function(done) { + + var xml = fs.readFileSync('test/fixtures/bpmn/error/di-plane-no-bpmn-element.bpmn', 'utf8'); + + var renderer = new Viewer(container); + + renderer.importXML(xml, function(err) { + + expect(err).toBeDefined(); + expect(err.message).toEqual('no rootElement referenced in BPMNPlane '); + + done(); + }); + }); + });