bool.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Should
  3. * Copyright(c) 2010-2014 TJ Holowaychuk <tj@vision-media.ca>
  4. * MIT Licensed
  5. */
  6. module.exports = function(should, Assertion) {
  7. /**
  8. * Assert given object is exactly `true`.
  9. *
  10. * @name true
  11. * @memberOf Assertion
  12. * @category assertion bool
  13. * @alias Assertion#True
  14. * @example
  15. *
  16. * (true).should.be.true();
  17. * false.should.not.be.true();
  18. *
  19. * ({ a: 10}).should.not.be.true();
  20. */
  21. Assertion.add('true', function() {
  22. this.is.exactly(true);
  23. });
  24. Assertion.alias('true', 'True');
  25. /**
  26. * Assert given object is exactly `false`.
  27. *
  28. * @name false
  29. * @memberOf Assertion
  30. * @category assertion bool
  31. * @alias Assertion#False
  32. * @example
  33. *
  34. * (true).should.not.be.false();
  35. * false.should.be.false();
  36. */
  37. Assertion.add('false', function() {
  38. this.is.exactly(false);
  39. });
  40. Assertion.alias('false', 'False');
  41. /**
  42. * Assert given object is thuthy according javascript type conversions.
  43. *
  44. * @name ok
  45. * @memberOf Assertion
  46. * @category assertion bool
  47. * @example
  48. *
  49. * (true).should.be.ok();
  50. * ''.should.not.be.ok();
  51. * should(null).not.be.ok();
  52. * should(void 0).not.be.ok();
  53. *
  54. * (10).should.be.ok();
  55. * (0).should.not.be.ok();
  56. */
  57. Assertion.add('ok', function() {
  58. this.params = { operator: 'to be truthy' };
  59. this.assert(this.obj);
  60. });
  61. };