Skip to content

Commit

Permalink
fix(crash): put try/catch around a test, close #6
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jul 21, 2017
1 parent 8f8a5ee commit 079a3f2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
30 changes: 30 additions & 0 deletions src/change-by-example-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,36 @@ describe('change-by-example', () => {
la(R.equals(output, expected), diff(expected, output).text)
})

it('should not crash on non-strings', () => {
const source = {
name: {
first: 'joe',
last: 'smith'
}
}
const destination = {
name: {
first: 'joe'
}
}
finds(source, destination)
})

it('works with nested objects', () => {
const source = {
age: 42,
name: {
first: 'joe',
last: 'smith'
}
}
const destination = {
first: 'Joe',
last: 'Smith'
}
finds(source, destination)
})

describe('delete property', () => {
const source = {
foo: 'f',
Expand Down
14 changes: 8 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ function o2o (source, destination) {
R.keys(source).some(key => {
const sourceValue = source[key]
const foundTransform = transforms.some(t => {
const out = t.f(sourceValue)
if (R.equals(value, out)) {
sourceKey = key
transform = t
return true
}
try {
const out = t.f(sourceValue)
if (R.equals(value, out)) {
sourceKey = key
transform = t
return true
}
} catch (e) {}
})
return foundTransform
})
Expand Down

0 comments on commit 079a3f2

Please sign in to comment.