str.js 758 B

123456789101112131415161718192021222324252627282930313233
  1. var test = require('tape');
  2. var stringify = require('../');
  3. test('simple object', function (t) {
  4. t.plan(1);
  5. var obj = { c: 6, b: [4,5], a: 3, z: null };
  6. t.equal(stringify(obj), '{"a":3,"b":[4,5],"c":6,"z":null}');
  7. });
  8. test('object with undefined', function (t) {
  9. t.plan(1);
  10. var obj = { a: 3, z: undefined };
  11. t.equal(stringify(obj), '{"a":3}');
  12. });
  13. test('array with undefined', function (t) {
  14. t.plan(1);
  15. var obj = [4, undefined, 6];
  16. t.equal(stringify(obj), '[4,null,6]');
  17. });
  18. test('object with empty string', function (t) {
  19. t.plan(1);
  20. var obj = { a: 3, z: '' };
  21. t.equal(stringify(obj), '{"a":3,"z":""}');
  22. });
  23. test('array with empty string', function (t) {
  24. t.plan(1);
  25. var obj = [4, '', 6];
  26. t.equal(stringify(obj), '[4,"",6]');
  27. });