fn.js 758 B

12345678910111213141516171819202122232425262728
  1. var inspect = require('../');
  2. var test = require('tape');
  3. test('function', function (t) {
  4. t.plan(1);
  5. var obj = [1, 2, function f(n) { return n; }, 4];
  6. t.equal(inspect(obj), '[ 1, 2, [Function: f], 4 ]');
  7. });
  8. test('function name', function (t) {
  9. t.plan(1);
  10. var f = (function () {
  11. return function () {};
  12. }());
  13. f.toString = function toStr() { return 'function xxx () {}'; };
  14. var obj = [1, 2, f, 4];
  15. t.equal(inspect(obj), '[ 1, 2, [Function (anonymous)] { toString: [Function: toStr] }, 4 ]');
  16. });
  17. test('anon function', function (t) {
  18. var f = (function () {
  19. return function () {};
  20. }());
  21. var obj = [1, 2, f, 4];
  22. t.equal(inspect(obj), '[ 1, 2, [Function (anonymous)], 4 ]');
  23. t.end();
  24. });