Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
feat: rule test supports function
Browse files Browse the repository at this point in the history
  • Loading branch information
tinymins committed May 17, 2019
1 parent 0dbd18c commit 5e23771
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ const Rule = Orderable(
}

if (!omit.includes('test') && 'test' in obj) {
this.test(obj.test instanceof RegExp ? obj.test : new RegExp(obj.test));
this.test(
obj.test instanceof RegExp || typeof obj.test === 'function'
? obj.test
: new RegExp(obj.test),
);
}

return super.merge(obj, [
Expand Down
9 changes: 9 additions & 0 deletions test/Rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ test('toConfig with values', t => {
});
});

test('toConfig with test function', t => {
const rule = new Rule();
const test = s => s.indexOf('.js') >= 0;

rule.test(test);

t.deepEqual(rule.toConfig(), { test });
});

test('merge empty', t => {
const rule = new Rule();
const obj = {
Expand Down

0 comments on commit 5e23771

Please sign in to comment.