From df119a82ac984e7ab67cf8eb4e4bf91c2060d4b5 Mon Sep 17 00:00:00 2001 From: Bruno Calou Date: Sat, 1 Oct 2022 14:37:00 -0300 Subject: [PATCH] test: add dom tests --- test/dom/index.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/dom/index.ts diff --git a/test/dom/index.ts b/test/dom/index.ts new file mode 100644 index 0000000000..e01e6d17c5 --- /dev/null +++ b/test/dom/index.ts @@ -0,0 +1,34 @@ +import * as assert from 'assert'; +import { detach } from 'svelte/internal'; + +describe('dom', () => { + describe('detach', () => { + describe('when parentNode exists', () => { + it('should detach the child from the parent', () => { + const parent = document.createElement('div'); + const child = document.createElement('div'); + parent.appendChild(child); + + assert.equal(child.parentElement, parent); + + detach(child); + + assert.equal(child.parentElement, null); + }); + }); + describe('when parentNode does not exist', () => { + it('should not throw an exception', () => { + const childWithoutParent = document.createElement('div'); + let error = null; + + try { + detach(childWithoutParent); + } catch (e) { + error = e; + } + + assert.equal(error, null); + }); + }); + }); +});