Skip to content

Commit

Permalink
improve tests 馃Ц
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb committed Mar 1, 2019
1 parent fc25f9a commit 67ea731
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,41 @@ import test from 'ava'
import {findAndReplace, findAndReplaceIf} from '../dist/index.cjs'

test('findAndReplace', t => {
let res
res = findAndReplace({a: {b: {c: 'a'}}}, 'a', 'b')
let res, ori
ori = {a: {b: {c: 'a'}}}
res = findAndReplace(ori, 'a', 'b')
t.deepEqual(res, {a: {b: {c: 'b'}}})
res = findAndReplace('_', 'a', 'b')
t.is(res, '_')
res = findAndReplace('a', 'a', 'b')
t.is(res, 'b')
})

test('findAndReplace does not modify objects', t => {
let res, ori
ori = {a: {b: {c: 'a'}, d: 1}}
res = findAndReplace(ori, 'a', 'b')
t.deepEqual(res, {a: {b: {c: 'b'}, d: 1}})
t.deepEqual(ori, {a: {b: {c: 'a'}, d: 1}})
res.a.b = 1
t.deepEqual(res, {a: {b: 1, d: 1}})
t.deepEqual(ori, {a: {b: {c: 'a'}, d: 1}})
res.a.d = 2
t.deepEqual(res, {a: {b: 1, d: 2}})
t.deepEqual(ori, {a: {b: {c: 'a'}, d: 1}})
ori.a.d = 3
t.deepEqual(res, {a: {b: 1, d: 2}})
t.deepEqual(ori, {a: {b: {c: 'a'}, d: 3}})
})

test('findAndReplace does not work with objects', t => {
let res, ori
ori = {a: {b: {c: 'a'}}}
res = findAndReplace(ori, {c: 'a'}, {c: 'b'})
t.deepEqual(res, {a: {b: {c: 'a'}}})
t.deepEqual(ori, {a: {b: {c: 'a'}}})
})

test('findAndReplaceIf', t => {
let res
function checkFn (foundVal) {
Expand Down

0 comments on commit 67ea731

Please sign in to comment.