diff options
-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/], + }); +}); |