Front end of the Slack clone application.

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var assert = require('assert');
  2. var mustCallChecks = [];
  3. function runCallChecks() {
  4. var failed_count = 0;
  5. for (var i=0 ; i< mustCallChecks.length; ++i) {
  6. var context = mustCallChecks[i];
  7. if (context.actual === context.expected) {
  8. continue;
  9. }
  10. failed_count++;
  11. console.log('Mismatched %s function calls. Expected %d, actual %d.',
  12. context.name,
  13. context.expected,
  14. context.actual);
  15. console.log(context.stack.split('\n').slice(2).join('\n'));
  16. }
  17. assert(failed_count === 0);
  18. }
  19. after(runCallChecks);
  20. exports.mustCall = function(fn, expected) {
  21. if (typeof expected !== 'number') expected = 1;
  22. var context = {
  23. expected: expected,
  24. actual: 0,
  25. stack: (new Error).stack,
  26. name: fn.name || '<anonymous>'
  27. };
  28. mustCallChecks.push(context);
  29. return function() {
  30. context.actual++;
  31. return fn.apply(this, arguments);
  32. };
  33. };