-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes-test.js
More file actions
38 lines (37 loc) · 1.29 KB
/
types-test.js
File metadata and controls
38 lines (37 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const _ = require('lodash');
const assert = require('assert');
const coreTypes = require('../src/types');
const {SerializedType} = require('../src/types/serialized-type');
describe('SerializedType interfaces', () => {
_.forOwn(coreTypes, (Value, name) => {
it(`${name} has a \`from\` static constructor`, () => {
assert(Value.from && Value.from !== Array.from);
});
it(`${name} has a default constructor`, () => {
/* eslint-disable no-new*/
new Value();
/* eslint-enable no-new*/
});
it(`${name}.from will return the same object`, () => {
const instance = new Value();
assert(Value.from(instance) === instance);
});
it(`${name} instances have toBytesSink`, () => {
assert(new Value().toBytesSink);
});
it(`${name} instances have toJSON`, () => {
assert(new Value().toJSON);
});
it(`${name}.from(json).toJSON() == json`, () => {
const newJSON = new Value().toJSON();
assert.deepEqual(Value.from(newJSON).toJSON(), newJSON);
});
describe(`${name} supports all methods of the SerializedType mixin`, () => {
_.keys(SerializedType).forEach(k => {
it(`new ${name}.prototype.${k} !== undefined`, () => {
assert.notEqual(Value.prototype[k], undefined);
});
});
});
});
});