From 9c8ef21d2f6d608184a023a27e5eac75e03cbb2f Mon Sep 17 00:00:00 2001 From: Max Franz Date: Fri, 7 Dec 2018 15:31:13 -0500 Subject: [PATCH] Add @josejulio's second test case, re: When using `cy.json`, sometimes some nodes are not being deleted #2231 --- test/core-graph-manipulation.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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();