to-json.js 607 B

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