test.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. describe('one-time', function () {
  2. 'use strict';
  3. var assume = require('assume')
  4. , one = require('./');
  5. it('is exported as a function', function () {
  6. assume(one).is.a('function');
  7. });
  8. it('only calls the supplied function once', function (next) {
  9. next = one(next);
  10. next();
  11. next();
  12. next();
  13. next();
  14. });
  15. it('returns the same value as the called function every single time', function () {
  16. var foo = one(function () {
  17. return 'bar';
  18. });
  19. assume(foo()).equals('bar');
  20. assume(foo()).equals('bar');
  21. assume(foo()).equals('bar');
  22. assume(foo()).equals('bar');
  23. assume(foo()).equals('bar');
  24. assume(foo()).equals('bar');
  25. assume(foo()).equals('bar');
  26. assume(foo()).equals('bar');
  27. assume(foo()).equals('bar');
  28. assume(foo()).equals('bar');
  29. assume(foo()).equals('bar');
  30. });
  31. it('the returned function uses the same displayName as the given fn', function () {
  32. var foo = one(function banana() {
  33. return 'bar';
  34. });
  35. assume(foo.displayName).equals('banana');
  36. });
  37. });