to-json.js 574 B

1234567891011121314151617181920
  1. var test = require('tape');
  2. var stringify = require('../');
  3. test('toJSON function', function (t) {
  4. t.plan(1);
  5. var obj = { one: 1, two: 2, toJSON: function() { return { one: 1 }; } };
  6. t.equal(stringify(obj), '{"one":1}' );
  7. });
  8. test('toJSON returns string', function (t) {
  9. t.plan(1);
  10. var obj = { one: 1, two: 2, toJSON: function() { return 'one'; } };
  11. t.equal(stringify(obj), '"one"');
  12. });
  13. test('toJSON returns array', function (t) {
  14. t.plan(1);
  15. var obj = { one: 1, two: 2, toJSON: function() { return ['one']; } };
  16. t.equal(stringify(obj), '["one"]');
  17. });