diff --git a/test/core-graph-manipulation.js b/test/core-graph-manipulation.js index b74f132b2..9803265a5 100644 --- a/test/core-graph-manipulation.js +++ b/test/core-graph-manipulation.js @@ -454,7 +454,7 @@ describe('Core graph manipulation', function(){ it('cy.json() can remove all elements', function() { // Issue #2231 var cb = 0; - cy.on('remove', function() { cb++ }); + cy.on('remove', function() { cb++; }); cy.json({ elements: { @@ -472,6 +472,28 @@ describe('Core graph manipulation', function(){ expect( cb ).to.equal(5); // 3 nodes and 2 edges }); + it('cy.json() removes all but last element', function(){ + // clean up before test: + cy.elements().remove(); + cy.add([ + { data: { id: 'a' } }, + { data: { id: 'b' } }, + { data: { id: 'c' } }, + { data: { id: 'd' } } + ]); + + cy.json({ + elements: [ + { data: { id: 'd' } } + ] + }); + + expect( cy.$('#a').empty(), 'node a not in graph' ).to.be.true; + expect( cy.$('#b').empty(), 'node b not in graph' ).to.be.true; + expect( cy.$('#c').empty(), 'node c not in graph' ).to.be.true; + expect( cy.$('#d').nonempty(), 'node d in graph' ).to.be.true; + }); + it('cy.json() removes parent', function(){ // clean up before test: cy.elements().remove();