Skip to content

Commit

Permalink
Fix bug when trying to use in on primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
bas080 committed Sep 20, 2022
1 parent 44db253 commit b109b85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ test('Matches always when pattern equals value', check(gen.any, (t, val) => {
patroon(val, () => t.end())(val)
}))

test('Matches when empty array matches with empty array', t => {
patroon([], () => t.end())([])
})

test('May or may not match with any value', check(gen.any, gen.any, (t, a, b) => {
patroon(
a, () => t.end(),
_, () => t.end()
)(b)
}))

test('Matches none of the patterns and throws', t => {
t.plan(1)
t.throws(() =>
Expand Down
4 changes: 2 additions & 2 deletions src/walkable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { isEmpty, isFunction, isNil } = require('./helpers')
const { isEmpty, isFunction, isNil, isPrimitive } = require('./helpers')

function walk (config, transform, item, path = []) {
if (config.isLeafe(item)) { return transform(item, path) }
Expand Down Expand Up @@ -52,7 +52,7 @@ function path (pth, v, errorData) {

const [key, ...rest] = pth

if (isNil(v) || !(key in v)) {
if (isPrimitive(v) || !(key in v)) {
const error = new PathError(
`Cannot read path ${pth}.`)

Expand Down

0 comments on commit b109b85

Please sign in to comment.