Skip to content

Commit

Permalink
fix tests on empty json
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlewind committed Jan 6, 2018
1 parent 0166666 commit f3b1c0a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/bumpover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function bumpRoot (node, options, bumpFn, resolve, reject) {
}

if (!Array.isArray(node[childKey])) {
resolve(node)
resolve(serializer(node) || defaultValue)
return
}

Expand Down
28 changes: 26 additions & 2 deletions test/json/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@ import test from 'ava'
import { JSONBumpover } from '../../lib'

test('empty data', async t => {
const input = JSON.stringify
const input = '{}'

const expected = '{}'

const rules = []

const bumper = new JSONBumpover(rules)

return bumper.bump(input).then(actual => t.deepEqual(actual, expected))
})

test('throw wrong data', async t => {
const input = ''

const rules = []

Expand All @@ -11,7 +23,19 @@ test('empty data', async t => {
await t.throws(bumper.bump(input))
})

test('empty data', async t => {
test('catch wrong data', async t => {
const input = ''

const noop = () => {}

const rules = []

const bumper = new JSONBumpover(rules)

await t.notThrows(bumper.bump(input).catch(noop))
})

test('nested data', t => {
const input = '{"id":1,"children":[{"id":2,"children":[{"id":3,"children":[{"id":4,"children":[]},{"id":5,"children":[]},{"id":6,"children":[]}]}]}]}'

const expected = '{"id":2,"children":[{"id":3,"children":[{"id":4,"children":[{"id":5,"children":[]},{"id":6,"children":[]},{"id":7,"children":[]}]}]}]}'
Expand Down
2 changes: 1 addition & 1 deletion test/xml/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const connect = arr => arr.map(line => line.trim()).join('')
test('empty data', t => {
const input = ''

const expected = {}
const expected = null

const rules = [
{
Expand Down

0 comments on commit f3b1c0a

Please sign in to comment.