Skip to content

Commit

Permalink
patch: return enforce from extend api
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jul 15, 2020
1 parent a386954 commit a215c43
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/n4s/dist/extended/enforce.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/n4s/dist/n4s.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/n4s/src/enforce/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ enforce.extend = customRules => {
if (!proxySupported()) {
rulesList = Object.keys(rulesObject);
}

return enforce;
};

export default enforce;
8 changes: 7 additions & 1 deletion packages/n4s/src/enforce/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@ const suite = ({ withProxy, requirePath }) =>
});

describe('Test custom rule extensions', () => {
let extended;
beforeEach(() => {
enforce.extend({
extended = enforce.extend({
isImpossible: v => !!v.match(/impossible/i),
endsWith: (v, arg) => v.endsWith(arg),
});
});

it('Should return enforce', () => {
expect(typeof extended).toBe('function');
expect(extended).toBe(enforce);
});

it('Should throw on failing custom rule in regular test', () => {
const t = () => enforce('The name is Snowball').endsWith('Snuffles');
expect(t).toThrow(Error);
Expand Down
2 changes: 1 addition & 1 deletion packages/vest/vest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ declare module 'vest' {
(value: any): IEnforceRules;

/**
* Creates a new enforce instance with custom rules
* Adds custom rules to enforce
* @param rules Rules object to add onto enforce
*
* @example
Expand Down

0 comments on commit a215c43

Please sign in to comment.