defaultsTo.test.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var assert = require('assert');
  2. var M = require('..');
  3. describe('inputs should respect defaultsTo', function() {
  4. var valueOfFooInFn;
  5. var valueOfBarInFn;
  6. var machine = {
  7. inputs: {
  8. foo: {
  9. example: 'foo bar',
  10. defaultsTo: 'foo@bar.com'
  11. },
  12. bar: {
  13. example: 2,
  14. required: true,
  15. defaultsTo: 23823
  16. }
  17. },
  18. exits: {
  19. success: {},
  20. error: {}
  21. },
  22. fn: function (inputs, exits, deps) {
  23. valueOfFooInFn=inputs.foo;
  24. valueOfBarInFn=inputs.bar;
  25. exits();
  26. }
  27. };
  28. it('should ignore `defaultsTo` for required inputs', function(done) {
  29. M.build(machine)
  30. .configure({})
  31. .exec(function(err, result) {
  32. assert(err, 'Expecting `err` because required input is missing.');
  33. done();
  34. });
  35. });
  36. it('should apply `defaultsTo` for optional inputs, if they have one', function(done) {
  37. M.build(machine)
  38. .configure({
  39. bar: 3
  40. })
  41. .exec(function(err, result) {
  42. if(err) return done(err);
  43. assert.equal(valueOfFooInFn, 'foo@bar.com');
  44. done();
  45. });
  46. });
  47. });