stringify.test.js 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. var util = require('util');
  2. var assert = require('assert');
  3. var _ = require('@sailshq/lodash');
  4. var rttc = require('../');
  5. describe('.stringify()', function() {
  6. it('should return a string in the general case', function() {
  7. assert.strictEqual(typeof rttc.stringify('foo'), 'string');
  8. assert.strictEqual(typeof rttc.stringify(''), 'string');
  9. assert.strictEqual(typeof rttc.stringify(2323), 'string');
  10. assert.strictEqual(typeof rttc.stringify(true), 'string');
  11. assert.strictEqual(typeof rttc.stringify(null), 'string');
  12. assert.strictEqual(typeof rttc.stringify(Infinity), 'string');
  13. assert.strictEqual(typeof rttc.stringify(-Infinity), 'string');
  14. assert.strictEqual(typeof rttc.stringify(NaN), 'string');
  15. assert.strictEqual(typeof rttc.stringify(new Error('wat')), 'string');
  16. assert.strictEqual(typeof rttc.stringify(new Buffer('stuff')), 'string');
  17. assert.strictEqual(typeof rttc.stringify({x:'foo',z: [{a:4}]}), 'string');
  18. });
  19. it('should return `"null"` (as a string) when attempting to stringify `undefined` with `allowNull` enabled', function() {
  20. assert.strictEqual(rttc.stringify(undefined, true), 'null');
  21. });
  22. it('should return `undefined` when attempting to stringify `undefined` with `allowNull` disabled (or unspecified)', function() {
  23. assert(_.isUndefined(rttc.stringify(undefined, false)));
  24. assert(_.isUndefined(rttc.stringify(undefined)));
  25. });
  26. });