Skip to content

Commit 10fc3db

Browse files
authored
use snapshot to verify the error message on invalid json (#31926)
1 parent 15c5357 commit 10fc3db

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
exports['invalid json error message'] = `
2+
'bad_json.json' is not valid JSON.
3+
Expected ',' or '}' after property value in JSON at position 20 (line 3 column 3) while parsing near "{\\n \\"bad\\": \\"json\\"\\n \\"should\\": \\"not parse..."
4+
`

packages/server/test/unit/fixture_spec.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const fixture = require(`../../lib/fixture`)
66
const { fs } = require(`../../lib/util/fs`)
77
const FixturesHelper = require('@tooling/system-tests')
88
const { getCtx } = require(`../../lib/makeDataContext`)
9+
const snapshot = require('snap-shot-it')
910

1011
let ctx
1112

@@ -68,14 +69,11 @@ describe('lib/fixture', () => {
6869

6970
context('json files', () => {
7071
it('throws when json is invalid', function () {
71-
const e =
72-
`\'bad_json.json\' is not valid JSON.\nExpected ',' or '}' after property value in JSON at position 20 while parsing near "{\\n \\"bad\\": \\"json\\"\\n \\"should\\": \\"not parse..."`
73-
7472
return fixture.get(this.fixturesFolder, 'bad_json.json')
7573
.then(() => {
7674
throw new Error('should have failed but did not')
7775
}).catch((err) => {
78-
expect(err.message).to.eq(e)
76+
snapshot('invalid json error message', err.message)
7977
})
8078
})
8179

0 commit comments

Comments
 (0)