From f610e332b3e31d9713724d701798e3f945da7311 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 22 Feb 2016 12:13:26 +0800 Subject: [PATCH] spec: Tests for remote ES6 class --- spec/api-ipc-spec.js | 37 +++++++++++++++++++++++++++++++++++ spec/fixtures/module/class.js | 29 +++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 spec/fixtures/module/class.js diff --git a/spec/api-ipc-spec.js b/spec/api-ipc-spec.js index 9cf741412b08..90e099fa612e 100644 --- a/spec/api-ipc-spec.js +++ b/spec/api-ipc-spec.js @@ -1,3 +1,5 @@ +'use strict'; + const assert = require('assert'); const path = require('path'); @@ -98,6 +100,41 @@ describe('ipc module', function() { }); }); + describe('remote class', function() { + let cl = remote.require(path.join(fixtures, 'module', 'class.js')); + let base = cl.base; + let derived = cl.derived; + + it('can get methods', function() { + assert.equal(base.method(), 'method'); + }); + + it('can get properties', function() { + assert.equal(base.readonly, 'readonly'); + }); + + it('can change properties', function() { + assert.equal(base.value, 'old'); + base.value = 'new'; + assert.equal(base.value, 'new'); + base.value = 'old'; + }); + + it('has unenumerable methods', function() { + assert(!base.hasOwnProperty('method')); + assert(Object.getPrototypeOf(base).hasOwnProperty('method')); + }); + + it('keeps prototype chain in derived class', function() { + assert.equal(derived.method(), 'method'); + assert.equal(derived.readonly, 'readonly'); + assert(!derived.hasOwnProperty('method')); + let proto = Object.getPrototypeOf(derived); + assert(!proto.hasOwnProperty('method')); + assert(Object.getPrototypeOf(proto).hasOwnProperty('method')); + }); + }); + describe('ipc.sender.send', function() { it('should work when sending an object containing id property', function(done) { var obj = { diff --git a/spec/fixtures/module/class.js b/spec/fixtures/module/class.js new file mode 100644 index 000000000000..f25eb2593ff3 --- /dev/null +++ b/spec/fixtures/module/class.js @@ -0,0 +1,29 @@ +'use strict'; + +let value = 'old'; + +class BaseClass { + method() { + return 'method'; + } + + get readonly() { + return 'readonly'; + } + + get value() { + return value; + } + + set value(val) { + value = val; + } +} + +class DerivedClass extends BaseClass { +} + +module.exports = { + base: new BaseClass, + derived: new DerivedClass, +}