From 562c0677ad463e8f2f752f227151f757eb8eb2b6 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli Date: Tue, 29 Jun 2021 18:21:21 -0400 Subject: [PATCH] chore(tests): demo example of Issue#48 --- README.md | 4 ++++ tests/unit/use-resource-test.ts | 30 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eb359078e..83c264632 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,10 @@ class MyResource extends LifecycleResource> { } ``` +These shorthands are 3 characters sharter than using the `named:` or +`positional: ` keys that would be required if not using these shorthands... + + ## Testing If your resources are consumed by components, you'll want to continue to diff --git a/tests/unit/use-resource-test.ts b/tests/unit/use-resource-test.ts index f4cc67e4d..ac3a8e4e8 100644 --- a/tests/unit/use-resource-test.ts +++ b/tests/unit/use-resource-test.ts @@ -17,7 +17,7 @@ module('useResource', function () { setupTest(hooks); test('it works', async function (assert) { - class Doubler extends LifecycleResource<{ positional: [number] }> { + class Doubler extends LifecycleResource> { @tracked num = 0; setup() { @@ -49,6 +49,34 @@ module('useResource', function () { assert.equal(foo.data.num, 8); }); + test('can take a typed array https://github.com/NullVoxPopuli/ember-resources/issues/48', async function (assert) { + class DoubleEverything extends LifecycleResource> { + @tracked result: number[] = []; + + setup() { + this.update(); + } + + update() { + this.result = this.args.positional.map((num) => num * 2); + } + } + class Test { + @tracked numbers = [0, 1, 2, 3]; + + data = useResource(this, DoubleEverything, () => [...this.numbers]); + } + + let foo = new Test(); + + await settled(); + assert.deepEqual(foo.data.result, [0, 2, 4, 6]); + + foo.numbers = [2, 6, 2, 7]; + await settled(); + assert.deepEqual(foo.data.result, [4, 12, 4, 14]); + }); + test('lifecycle', async function (assert) { class Doubler extends LifecycleResource<{ positional: [number] }> { @tracked num = 0;