strict-option-test.js 929 B

12345678910111213141516171819202122232425262728
  1. var mocha = require('mocha'),
  2. assert = require('chai').assert,
  3. expect = require('chai').expect;
  4. describe("Testing 'strict' option", function () {
  5. var dupkeys = '{ "dupkey": "value 1", "dupkey": "value 2"}';
  6. it('Should show that duplicate keys just get overwritten by default', function (done) {
  7. var JSONbig = require('../index');
  8. var result = 'before';
  9. function tryParse() {
  10. result = JSONbig.parse(dupkeys);
  11. }
  12. expect(tryParse).to.not.throw('anything');
  13. expect(result.dupkey).to.equal('value 2');
  14. done();
  15. });
  16. it("Should show that the 'strict' option will fail-fast on duplicate keys", function (done) {
  17. var JSONstrict = require('../index')({ strict: true });
  18. var result = 'before';
  19. function tryParse() {
  20. result = JSONstrict.parse(dupkeys);
  21. }
  22. expect(tryParse).to.throw('Duplicate key "dupkey"');
  23. expect(result).to.equal('before');
  24. done();
  25. });
  26. });