|
| 1 | +// Copyright 2017-2022 @polkadot/api-contract authors & contributors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import type { Namespaced } from './types'; |
| 5 | + |
| 6 | +import { expandNs } from './util'; |
| 7 | + |
| 8 | +type TestNS = Namespaced<string>; |
| 9 | + |
| 10 | +describe('expandNs', (): void => { |
| 11 | + it('expands into single-namespaced and normal location', (): void => { |
| 12 | + const testNs: TestNS = {}; |
| 13 | + const test: Record<string, string> = {}; |
| 14 | + |
| 15 | + test.a = expandNs(testNs, { path: ['ns_a'] }, 'a'); |
| 16 | + |
| 17 | + expect(test.a).toEqual('a'); |
| 18 | + expect(testNs.ns_a).toEqual('a'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('expands into multi-namespaced and normal location', (): void => { |
| 22 | + const testNs: TestNS = {}; |
| 23 | + |
| 24 | + expect(expandNs(testNs, { path: ['A', 'B', 'a'] }, 'a')).toEqual('a'); |
| 25 | + |
| 26 | + expect(testNs.A.B.a).toEqual('a'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('it expands multiples', (): void => { |
| 30 | + const testNs: TestNS = {}; |
| 31 | + |
| 32 | + expect(expandNs(testNs, { path: ['A', 'B', 'a'] }, 'a')).toEqual('a'); |
| 33 | + expect(expandNs(testNs, { path: ['A', 'B', 'b'] }, 'b')).toEqual('b'); |
| 34 | + expect(expandNs(testNs, { path: ['A', 'C', 'c'] }, 'c')).toEqual('c'); |
| 35 | + |
| 36 | + expect(testNs.A.B.a).toEqual('a'); |
| 37 | + expect(testNs.A.B.b).toEqual('b'); |
| 38 | + expect(testNs.A.C.c).toEqual('c'); |
| 39 | + }); |
| 40 | +}); |
0 commit comments