diff --git a/src/Rule.js b/src/Rule.js index 954243e..8479937 100644 --- a/src/Rule.js +++ b/src/Rule.js @@ -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, [ diff --git a/test/Rule.js b/test/Rule.js index 03e9d7d..e6608db 100644 --- a/test/Rule.js +++ b/test/Rule.js @@ -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 = {