From b109b8515a41e035deb479594a1a5c9850d9f05e Mon Sep 17 00:00:00 2001 From: Bas Huis Date: Tue, 20 Sep 2022 17:50:54 +0200 Subject: [PATCH] Fix bug when trying to use in on primitive --- src/index.test.js | 11 +++++++++++ src/walkable.js | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/index.test.js b/src/index.test.js index 471971a..37c8465 100755 --- a/src/index.test.js +++ b/src/index.test.js @@ -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(() => diff --git a/src/walkable.js b/src/walkable.js index 25f439a..298e265 100644 --- a/src/walkable.js +++ b/src/walkable.js @@ -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) } @@ -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}.`)