Files
common/packages/util/src/stringify.spec.ts
T
Jaco 306592f6b1 Bump bn.js (#1401)
* Bump bn.js

* Adjust expecatation
2022-02-07 11:59:57 +02:00

32 lines
839 B
TypeScript

// Copyright 2017-2022 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { BN } from './bn';
import { stringify } from './stringify';
describe('stringify', (): void => {
it('stringifies a BigInt', (): void => {
expect(
stringify(1234n)
).toEqual('"1234"');
});
it('stringifies an array of values', (): void => {
expect(
stringify(['a', 1, 2n, new BN(69)])
).toEqual('["a",1,"2","45"]');
});
it('stringifies an array of values (with spaces)', (): void => {
expect(
stringify(['a', 1, 2n, new BN(3)], 2)
).toEqual('[\n "a",\n 1,\n "2",\n "03"\n]');
});
it('stringifies a nested object', (): void => {
expect(
stringify({ a: 'a', b: 1, c: { d: 2n, e: new BN(3) } })
).toEqual('{"a":"a","b":1,"c":{"d":"2","e":"03"}}');
});
});