From d2a2887d3232040da0504699afcfc2c791734416 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 15 Oct 2020 09:22:04 +0200 Subject: [PATCH] Add explicit normalizer test (#2730) * Add explicit normalizer test * More expansive * nested --- packages/rpc-core/src/normalizer.spec.ts | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 packages/rpc-core/src/normalizer.spec.ts diff --git a/packages/rpc-core/src/normalizer.spec.ts b/packages/rpc-core/src/normalizer.spec.ts new file mode 100644 index 0000000000..391ca08e2c --- /dev/null +++ b/packages/rpc-core/src/normalizer.spec.ts @@ -0,0 +1,30 @@ +// Copyright 2017-2020 @polkadot/rpc-core authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import normalizer from './normalizer'; + +describe('normalizer', (): void => { + it('works when BigInt is in the data (object)', (): void => { + expect( + normalizer('instance')({ a: 'bar', b: 1234567890987654321n, c: 123 }) + ).toEqual('instance{"a":"bar","b":"1234567890987654321","c":123}'); + }); + + it('works when BigInt is in the data (array)', (): void => { + expect( + normalizer('instance')(['bar', 1234567890987654321n, 123]) + ).toEqual('instance["bar","1234567890987654321",123]'); + }); + + it('works when BigInt is in the data (single)', (): void => { + expect( + normalizer('instance')(1234567890987654321n) + ).toEqual('instance"1234567890987654321"'); + }); + + it('works when BigInt is in the data (nested)', (): void => { + expect( + normalizer('instance')({ a: 'bar', b: { foo: 1234567890987654321n }, c: 123 }) + ).toEqual('instance{"a":"bar","b":{"foo":"1234567890987654321"},"c":123}'); + }); +});