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/exposeDependency.js | |
parent | e304bebf19340b825df10a17315b534f5dca0219 (diff) |
data, test: exposeDependency (unit)
Diffstat (limited to 'test/unit/data/composite/exposeDependency.js')
-rw-r--r-- | test/unit/data/composite/exposeDependency.js | 80 |
1 files changed, 80 insertions, 0 deletions
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/], + }); +}); |