From 4fc79fdbdf910b6fc85802960c9bd7e93f350a02 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Thu, 13 Aug 2020 17:35:55 -0700 Subject: [PATCH] chore: add `class.inheritance` tests --- test/suites/class.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/suites/class.js b/test/suites/class.js index 752ebf4..9d22d7e 100644 --- a/test/suites/class.js +++ b/test/suites/class.js @@ -108,5 +108,41 @@ export default function (klona) { assert.equal(output.val, 42); }); + Classes('inheritance', () => { + class Animal { + constructor() { + this.cute = true; + } + get carbon() { + return true; + } + } + + class Dog extends Animal { + constructor(name) { + super(); + this.name = name; + } + bark() { + console.log('woof'); + } + } + + const input = new Dog('spot'); + const output = klona(input); + + assert.deepEqual(input, output); + assert.deepEqual(input.name, output.name); + assert.equal(output instanceof Animal, true); + assert.deepEqual(output.constructor, Dog); + assert.deepEqual(output.__proto__, {}); + assert.equal(output.carbon, true); + + assert.deepStrictEqual( + Object.getOwnPropertyDescriptors(input), + Object.getOwnPropertyDescriptors(output), + ); + }); + Classes.run(); }