Skip to content

Commit f610e33

Browse files
committed
spec: Tests for remote ES6 class
1 parent 67324ce commit f610e33

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

spec/api-ipc-spec.js

+37
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const assert = require('assert');
24
const path = require('path');
35

@@ -98,6 +100,41 @@ describe('ipc module', function() {
98100
});
99101
});
100102

103+
describe('remote class', function() {
104+
let cl = remote.require(path.join(fixtures, 'module', 'class.js'));
105+
let base = cl.base;
106+
let derived = cl.derived;
107+
108+
it('can get methods', function() {
109+
assert.equal(base.method(), 'method');
110+
});
111+
112+
it('can get properties', function() {
113+
assert.equal(base.readonly, 'readonly');
114+
});
115+
116+
it('can change properties', function() {
117+
assert.equal(base.value, 'old');
118+
base.value = 'new';
119+
assert.equal(base.value, 'new');
120+
base.value = 'old';
121+
});
122+
123+
it('has unenumerable methods', function() {
124+
assert(!base.hasOwnProperty('method'));
125+
assert(Object.getPrototypeOf(base).hasOwnProperty('method'));
126+
});
127+
128+
it('keeps prototype chain in derived class', function() {
129+
assert.equal(derived.method(), 'method');
130+
assert.equal(derived.readonly, 'readonly');
131+
assert(!derived.hasOwnProperty('method'));
132+
let proto = Object.getPrototypeOf(derived);
133+
assert(!proto.hasOwnProperty('method'));
134+
assert(Object.getPrototypeOf(proto).hasOwnProperty('method'));
135+
});
136+
});
137+
101138
describe('ipc.sender.send', function() {
102139
it('should work when sending an object containing id property', function(done) {
103140
var obj = {

spec/fixtures/module/class.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
let value = 'old';
4+
5+
class BaseClass {
6+
method() {
7+
return 'method';
8+
}
9+
10+
get readonly() {
11+
return 'readonly';
12+
}
13+
14+
get value() {
15+
return value;
16+
}
17+
18+
set value(val) {
19+
value = val;
20+
}
21+
}
22+
23+
class DerivedClass extends BaseClass {
24+
}
25+
26+
module.exports = {
27+
base: new BaseClass,
28+
derived: new DerivedClass,
29+
}

0 commit comments

Comments
 (0)