dehydrate.test.js 944 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var assert = require('assert');
  2. var rttc = require('../');
  3. describe('.dehydrate()', function() {
  4. it('should normally not run toJSON() methods on dictionaries', function() {
  5. var THING = {foo: 'bar', toJSON: function(){ return 'toJSON-ed thing'; } };
  6. assert.deepEqual(
  7. rttc.dehydrate(THING),
  8. {
  9. foo: 'bar',
  10. toJSON: rttc.dehydrate(function(){ return 'toJSON-ed thing'; })
  11. }
  12. );
  13. assert.deepEqual(
  14. rttc.dehydrate(THING, undefined, undefined, undefined, true),
  15. 'toJSON-ed thing'
  16. );
  17. });
  18. it('should NEVER run toJSON() methods on arrays', function() {
  19. var THING = ['foo', 'bar', 'baz'];
  20. THING.toJSON = function(){ return 'toJSON-ed thing'; };
  21. assert.deepEqual(
  22. rttc.dehydrate(THING),
  23. ['foo', 'bar', 'baz']
  24. );
  25. assert.deepEqual(
  26. rttc.dehydrate(THING, undefined, undefined, undefined, true),
  27. ['foo', 'bar', 'baz']
  28. );
  29. });
  30. });