declapract
Version:
A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.
27 lines • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const parseJSON_1 = require("./parseJSON");
describe('parseJSON', () => {
it('should be able to parse normal json', () => {
const original = { hello: 'world' };
const output = (0, parseJSON_1.parseJSON)(JSON.stringify(original));
expect(output).toEqual(original);
});
it('should be able to parse json5', () => {
const input = `{"hello": "world", }`; // note the trailing comma
const output = (0, parseJSON_1.parseJSON)(input);
expect(output).toEqual({ hello: 'world' });
});
it('should throw an error if neither is able to parse', () => {
const input = `{"hello": z "world", }`; // note the random z
try {
(0, parseJSON_1.parseJSON)(input);
throw new Error('should not reach here');
}
catch (error) {
expect(error).toBeInstanceOf(parseJSON_1.JSONParsingError);
expect(error.message).toContain(`Could not parse contents as neither JSON nor JSON5.`);
}
});
});
//# sourceMappingURL=parseJSON.test.js.map