|
| 1 | +import typeSafeGet, { overrideGet } from 'ember-typescript-utils/utils/type-safe-get'; |
| 2 | +import { module, test } from 'qunit'; |
| 3 | + |
| 4 | +module('Unit | Utility | type-safe-get', function(_hooks) { |
| 5 | + |
| 6 | + test('it works', function(assert) { |
| 7 | + const test = {a: {b: {c: {d: {e: {f: {g: {h: 'made it!'}}}}}}}}; |
| 8 | + |
| 9 | + assert.deepEqual(typeSafeGet(test, 'a'), test.a); |
| 10 | + assert.deepEqual(typeSafeGet(test, 'a', 'b'), test.a.b); |
| 11 | + assert.deepEqual(typeSafeGet(test, 'a', 'b', 'c'), test.a.b.c); |
| 12 | + assert.deepEqual(typeSafeGet(test, 'a', 'b', 'c', 'd'), test.a.b.c.d); |
| 13 | + assert.deepEqual(typeSafeGet(test, 'a', 'b', 'c', 'd', 'e'), test.a.b.c.d.e); |
| 14 | + assert.deepEqual(typeSafeGet(test, 'a', 'b', 'c', 'd', 'e', 'f'), test.a.b.c.d.e.f); |
| 15 | + assert.deepEqual(typeSafeGet(test, 'a', 'b', 'c', 'd', 'e', 'f', 'g'), test.a.b.c.d.e.f.g); |
| 16 | + assert.deepEqual(typeSafeGet(test, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'), test.a.b.c.d.e.f.g.h); |
| 17 | + }); |
| 18 | + |
| 19 | + test('overrideGet also works', function(assert) { |
| 20 | + const test = {a: {b: {c: {d: {e: {f: {g: {h: 'made it!'}}}}}}}}; |
| 21 | + |
| 22 | + assert.deepEqual(overrideGet(test, 'a'), test.a); |
| 23 | + assert.deepEqual(overrideGet(test, 'a', 'b'), test.a.b); |
| 24 | + assert.deepEqual(overrideGet(test, 'a', 'b', 'c'), test.a.b.c); |
| 25 | + assert.deepEqual(overrideGet(test, 'a', 'b', 'c', 'd'), test.a.b.c.d); |
| 26 | + assert.deepEqual(overrideGet(test, 'a', 'b', 'c', 'd', 'e'), test.a.b.c.d.e); |
| 27 | + assert.deepEqual(overrideGet(test, 'a', 'b', 'c', 'd', 'e', 'f'), test.a.b.c.d.e.f); |
| 28 | + assert.deepEqual(overrideGet(test, 'a', 'b', 'c', 'd', 'e', 'f', 'g'), test.a.b.c.d.e.f.g); |
| 29 | + assert.deepEqual(overrideGet(test, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'), test.a.b.c.d.e.f.g.h); |
| 30 | + }); |
| 31 | + |
| 32 | + test('it returns undefined if the initial object is undefined', function(assert) { |
| 33 | + let nothing!: {oops: 'this is just a type, not a value'}; |
| 34 | + assert.equal(typeSafeGet(nothing, 'oops'), undefined); |
| 35 | + }); |
| 36 | +}); |
0 commit comments