transferFlags.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*!
  2. * Chai - transferFlags utility
  3. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4. * MIT Licensed
  5. */
  6. /**
  7. * ### transferFlags(assertion, object, includeAll = true)
  8. *
  9. * Transfer all the flags for `assertion` to `object`. If
  10. * `includeAll` is set to `false`, then the base Chai
  11. * assertion flags (namely `object`, `ssfi`, and `message`)
  12. * will not be transferred.
  13. *
  14. *
  15. * var newAssertion = new Assertion();
  16. * utils.transferFlags(assertion, newAssertion);
  17. *
  18. * var anotherAsseriton = new Assertion(myObj);
  19. * utils.transferFlags(assertion, anotherAssertion, false);
  20. *
  21. * @param {Assertion} assertion the assertion to transfer the flags from
  22. * @param {Object} object the object to transfer the flags to; usually a new assertion
  23. * @param {Boolean} includeAll
  24. * @name transferFlags
  25. * @api private
  26. */
  27. module.exports = function (assertion, object, includeAll) {
  28. var flags = assertion.__flags || (assertion.__flags = Object.create(null));
  29. if (!object.__flags) {
  30. object.__flags = Object.create(null);
  31. }
  32. includeAll = arguments.length === 3 ? includeAll : true;
  33. for (var flag in flags) {
  34. if (includeAll ||
  35. (flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
  36. object.__flags[flag] = flags[flag];
  37. }
  38. }
  39. };