MCPcopy Create free account
hub / github.com/nodejs/node-addon-api / testStaticAccessor

Function testStaticAccessor

test/objectwrap.js:162–219  ·  view source on GitHub ↗
(clazz)

Source from the content-addressed store, hash-verified

160 };
161
162 const testStaticAccessor = (clazz) => {
163 // read-only, write-only
164 {
165 const tempObj = {};
166 clazz.testStaticSetter = tempObj;
167 assert.strictEqual(clazz.testStaticGetter, tempObj);
168 assert.strictEqual(clazz.testStaticGetterT, tempObj);
169
170 const tempArray = [];
171 clazz.testStaticSetter = tempArray;
172 assert.strictEqual(clazz.testStaticGetter, tempArray);
173 assert.strictEqual(clazz.testStaticGetterT, tempArray);
174 }
175
176 // read write-only
177 {
178 let error;
179 // eslint-disable-next-line no-unused-vars
180 try { const read = clazz.testStaticSetter; } catch (e) { error = e; }
181 // no error
182 assert.strictEqual(error, undefined);
183
184 // read is undefined
185 assert.strictEqual(clazz.testStaticSetter, undefined);
186 }
187
188 // write-read-only
189 {
190 let error;
191 try { clazz.testStaticGetter = 'write'; } catch (e) { error = e; }
192 assert.strictEqual(error.name, 'TypeError');
193 try { clazz.testStaticGetterT = 'write'; } catch (e) { error = e; }
194 assert.strictEqual(error.name, 'TypeError');
195 }
196
197 // rw
198 {
199 clazz.testStaticGetSet = 9;
200 assert.strictEqual(clazz.testStaticGetSet, 9);
201
202 clazz.testStaticGetSet = 4;
203 assert.strictEqual(clazz.testStaticGetSet, 4);
204
205 clazz.testStaticGetSetT = -9;
206 assert.strictEqual(clazz.testStaticGetSetT, -9);
207
208 clazz.testStaticGetSetT = -4;
209 assert.strictEqual(clazz.testStaticGetSetT, -4);
210 }
211
212 // rw symbol
213 {
214 clazz[clazz.kTestStaticAccessorInternal] = 'static internal getset';
215 assert.strictEqual(clazz[clazz.kTestStaticAccessorInternal], 'static internal getset');
216 clazz[clazz.kTestStaticAccessorTInternal] = 'static internal getset <>';
217 assert.strictEqual(clazz[clazz.kTestStaticAccessorTInternal], 'static internal getset <>');
218 }
219 };

Callers 1

testClassFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected