Skip to content

Commit

Permalink
fix(viewer): do not clear diagram if no diagram to clear
Browse files Browse the repository at this point in the history
Closes #1181
  • Loading branch information
philippfromme authored and fake-join[bot] committed Sep 20, 2019
1 parent 83e9f05 commit f177a46
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,11 @@ Viewer.prototype.getModules = function() {
* @method Viewer#clear
*/
Viewer.prototype.clear = function() {
if (!this.getDefinitions()) {

// no diagram to clear
return;
}

// remove businessObject#di binding
//
Expand Down
19 changes: 19 additions & 0 deletions test/spec/ViewerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,25 @@ describe('Viewer', function() {

describe('#clear', function() {

it('should NOT clear if no diagram', function() {

// given
var viewer = new Viewer({ container: container });

var eventBus = viewer.get('eventBus');

var spy = sinon.spy();

eventBus.on('diagram.clear', spy);

// when
viewer.clear();

// then
expect(spy).not.to.have.been.called;
});


it('should not throw if diagram is already empty', function() {

// given
Expand Down

0 comments on commit f177a46

Please sign in to comment.