str.js 765 B

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