diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-09-23 22:15:49 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-09-23 22:15:49 -0300 |
commit | 942b05a2beed7d28e93ae256de0f58be5b7e385a (patch) | |
tree | c5df39c907a26c5e0a473542467ac35ae876afa9 /test/unit/data/composite | |
parent | e304bebf19340b825df10a17315b534f5dca0219 (diff) |
data, test: exposeDependency (unit)
Diffstat (limited to 'test/unit/data/composite')
-rw-r--r-- | test/unit/data/composite/compositeFrom.js | 8 | ||||
-rw-r--r-- | test/unit/data/composite/exposeDependency.js | 80 |
2 files changed, 81 insertions, 7 deletions
diff --git a/test/unit/data/composite/compositeFrom.js b/test/unit/data/composite/compositeFrom.js index 6ae1e7bc..06a66e61 100644 --- a/test/unit/data/composite/compositeFrom.js +++ b/test/unit/data/composite/compositeFrom.js @@ -1,14 +1,8 @@ import t from 'tap'; +import {compositeFrom, continuationSymbol, input} from '#composite'; import {isString} from '#validators'; -import { - compositeFrom, - continuationSymbol, - debugComposite, - input, -} from '#composite'; - t.test(`compositeFrom: basic behavior`, t => { t.plan(2); diff --git a/test/unit/data/composite/exposeDependency.js b/test/unit/data/composite/exposeDependency.js new file mode 100644 index 00000000..7487e44c --- /dev/null +++ b/test/unit/data/composite/exposeDependency.js @@ -0,0 +1,80 @@ +import t from 'tap'; + +import { + compositeFrom, + continuationSymbol, + exposeDependency, + input, +} from '#composite'; + +t.test(`exposeDependency: basic behavior`, t => { + t.plan(4); + + const composite1 = compositeFrom({ + compose: false, + + steps: [ + exposeDependency({dependency: 'foo'}), + ], + }); + + t.match(composite1, { + expose: { + dependencies: ['foo'], + }, + }); + + t.equal(composite1.expose.compute({foo: 'bar'}), 'bar'); + + const composite2 = compositeFrom({ + compose: false, + + steps: [ + { + dependencies: ['foo'], + compute: (continuation, {foo}) => + continuation({'#bar': foo.toUpperCase()}), + }, + + exposeDependency({dependency: '#bar'}), + ], + }); + + t.match(composite2, { + expose: { + dependencies: ['foo'], + }, + }); + + t.equal(composite2.expose.compute({foo: 'bar'}), 'BAR'); +}); + +t.test(`exposeDependency: validate inputs`, t => { + t.plan(2); + + let caughtError; + + try { + caughtError = null; + exposeDependency({}); + } catch (error) { + caughtError = error; + } + + t.match(caughtError, { + errors: [/Required these inputs: dependency/], + }); + + try { + caughtError = null; + exposeDependency({ + dependency: input.value('some static value'), + }); + } catch (error) { + caughtError = error; + } + + t.match(caughtError, { + errors: [/Expected static dependencies: dependency/], + }); +}); |