sanity.test.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * Module dependencies
  3. */
  4. var util = require('util');
  5. var _ = require('@sailshq/lodash');
  6. var parley = require('../');
  7. /**
  8. * sanity.test.js
  9. *
  10. * A test of parley's most basic usage.
  11. *
  12. * > This is really just a sanity check to make sure there are no
  13. * > unexpected problems in the simplest assumptions of this module.
  14. */
  15. describe('parley()', function() {
  16. it('should throw', function(){
  17. try { parley(); }
  18. catch (e) { return; }
  19. throw new Error('Should have thrown an Error');
  20. });
  21. });
  22. describe('parley(handleExec)', function() {
  23. describe('with invalid handleExec', function (){
  24. it('should throw', function(){
  25. try { parley(123); }
  26. catch (e) { return; }
  27. throw new Error('Should have thrown an Error');
  28. });
  29. it('should throw', function(){
  30. try { parley([123, 456]); }
  31. catch (e) { return; }
  32. throw new Error('Should have thrown an Error');
  33. });
  34. });
  35. describe('with valid handleExec', function (){
  36. var π;
  37. it('should not throw', function(){
  38. π = parley(function (done){ return done(); });
  39. });
  40. it('should have returned an object of some sort', function(){
  41. if (!_.isObject(π)) { throw new Error('Instead got: '+util.inspect(π,{depth:5})+''); }
  42. });
  43. describe('deferred object (the "parley" itself)', function (){
  44. it('should have an `.exec()` method', function(){
  45. if (!_.isFunction(π.exec)) { throw new Error('Instead got: '+util.inspect(π.exec,{depth:5})+''); }
  46. });
  47. it('should have a `.then()` method', function(){
  48. if (!_.isFunction(π.then)) { throw new Error('Instead got: '+util.inspect(π.then,{depth:5})+''); }
  49. });
  50. it('should have a `.catch()` method', function(){
  51. if (!_.isFunction(π.catch)) { throw new Error('Instead got: '+util.inspect(π.catch,{depth:5})+''); }
  52. });
  53. it('should have a `.toPromise()` method', function(){
  54. if (!_.isFunction(π.toPromise)) { throw new Error('Instead got: '+util.inspect(π.toPromise,{depth:5})+''); }
  55. });
  56. });
  57. });
  58. });