Files
api/packages/api-codec/src/codec/Struct.spec.js
T
Jaco Greeff 0c906e54f8 Properly toJSON() on StorageFunction (#179)
* Properly toJSON() on StorageFunction

* Add isZero(), cmp & toStringFormat

* Update tests for UInt toString()
2018-10-01 16:33:01 +02:00

49 lines
1.0 KiB
JavaScript

// Copyright 2017-2018 @polkadot/api-codec authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import Struct from './Struct';
import Text from '../Text';
import U32 from '../U32';
describe('Struct', () => {
it('provides a clean toString()', () => {
expect(
new (
Struct.with({
txt: Text,
u32: U32
})
)({ txt: 'foo', u32: 0x123456 }).toString()
).toEqual(`{txt: foo, u32: 1193046}`);
});
it('exposes the types', () => {
expect(
new Struct({
foo: Text,
bar: Text,
baz: U32
}).Type
).toEqual({
foo: 'Text',
bar: 'Text',
baz: 'U32'
});
});
it('exposes the keys/values', () => {
const test = new Struct({
foo: Text,
bar: U32
}, { foo: 'bazzing', bar: 69 });
expect(test.keys()).toEqual(['foo', 'bar']);
expect(
test.values().map((v) =>
v.toString()
)
).toEqual(['bazzing', '69']);
});
});