Skip to content

Commit

Permalink
fix: exec returns array (not Match) in match(v, obj) with func conseq…
Browse files Browse the repository at this point in the history
…uent
  • Loading branch information
brigand committed Dec 27, 2019
1 parent 3f2db98 commit 220399e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function match(...values) {
const maybeMatch = cond.exec(...values);
if (maybeMatch && maybeMatch.values) {
if (typeof consequent === 'function') {
result = new Match(consequent(...maybeMatch.values));
result = new Match(consequent(...maybeMatch));
} else {
result = new Match(consequent);
}
Expand Down
6 changes: 3 additions & 3 deletions src/match.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ it(`works for simple conditions`, () => {
[LenEq(1)]: 'len 1',
[LenEq(2)]: 'len 2',
[Test((x) => x === 'bar')]: 'is bar',
[LenEq(3)]: 'len 3',
[LenEq(3)]: () => 'len 3',
[LenEq(4)]: 'len 4',
_: 'default',
}),
Expand All @@ -50,9 +50,9 @@ it(`works with exec arg passed to chain`, () => {
const results = ['', 'f', 'fo', 'foo', 'bar', 'food'].map((word) =>
match(word)
.with(LenEq(1), 'len 1')
.with(LenEq(2), 'len 2')
.with(LenEq(2), () => 'len 2')
.with(Eq('bar'), 'is bar')
.with(LenEq(3), 'len 3')
.with(LenEq(3), () => 'len 3')
.with(LenEq(4), 'len 4')
.any('default')
.exec(),
Expand Down

0 comments on commit 220399e

Please sign in to comment.