Handle invalid json

- fix style
This commit is contained in:
Thomas Nordquist
2019-06-04 14:36:28 +02:00
parent e66f6d098a
commit 09151d14a9
4 changed files with 58 additions and 25 deletions

View File

@@ -1,28 +1,28 @@
import 'mocha'
import { expect } from 'chai'
import { parseJson } from '../JsonAstParser'
import 'mocha'
const dotProp = require('dot-prop')
describe('access JSON values via dot property paths', () => {
it('object with literal', () => {
let data = {
const data = {
foo: 4,
}
let result = parseJson(JSON.stringify(data, undefined, 2))
const result = parseJson(JSON.stringify(data, undefined, 2))
expect(result[0].path).to.eq('foo')
expect(result[0].line).to.eq(2)
})
it('nested object', () => {
let data = {
const data = {
foo: {
bar: 4
bar: 4,
},
}
let result = parseJson(JSON.stringify(data, undefined, 2))
const result = parseJson(JSON.stringify(data, undefined, 2))
expect(result[0].path).to.eq('foo.bar')
expect(result[0].line).to.eq(3)
expect(dotProp.get(data, result[0].path)).to.eq(4)
@@ -30,7 +30,7 @@ describe('access JSON values via dot property paths', () => {
})
it('array path', () => {
let data = {
const data = {
foo: [
1,
2,
@@ -38,11 +38,17 @@ describe('access JSON values via dot property paths', () => {
],
}
let result = parseJson(JSON.stringify(data, undefined, 2))
const result = parseJson(JSON.stringify(data, undefined, 2))
expect(result.length).to.eq(3)
expect(result[2].path).to.eq('foo.2')
expect(result[2].line).to.eq(5)
expect(dotProp.get(data, result[2].path)).to.eq(3)
})
it('should fail parsing invalid json', () => {
expect(() => {
const result = parseJson("BLE2MQTT-8C48")
}).to.throw()
})
})