-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/vest/src/core/test/lib/__tests__/runLazyRules.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import runLazyRules from 'runLazyRules'; | ||
|
||
describe('runLazyRules', () => { | ||
describe('When single rule passed', () => { | ||
it('Should run rule against value', () => { | ||
const rule = { test: jest.fn(() => true) }; | ||
const value = { x: true }; | ||
runLazyRules(rule, value); | ||
expect(rule.test).toHaveBeenCalledWith(value); | ||
}); | ||
|
||
it('Should return true when successful', () => { | ||
const res = runLazyRules({ test: () => true }, 'some_value'); | ||
expect(res).toBe(true); | ||
}); | ||
|
||
it('Should return true when failing', () => { | ||
const res = runLazyRules({ test: () => false }, 'some_value'); | ||
expect(res).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('When an array of rules passed', () => { | ||
it('Should run each rule against value', () => { | ||
const rule_1 = { test: jest.fn(() => true) }; | ||
const rule_2 = { test: jest.fn(() => true) }; | ||
const rule_3 = { test: jest.fn(() => true) }; | ||
const value = { x: true }; | ||
runLazyRules([rule_1, rule_2, rule_3], value); | ||
expect(rule_1.test).toHaveBeenCalledWith(value); | ||
expect(rule_2.test).toHaveBeenCalledWith(value); | ||
expect(rule_3.test).toHaveBeenCalledWith(value); | ||
}); | ||
|
||
it('Should return true when successful', () => { | ||
const rule_1 = { test: () => true }; | ||
const rule_2 = { test: () => true }; | ||
const rule_3 = { test: () => true }; | ||
const res = runLazyRules([rule_1, rule_2, rule_3], 'some_value'); | ||
expect(res).toBe(true); | ||
}); | ||
|
||
it('Should return false when false', () => { | ||
const rule_1 = { test: () => false }; | ||
const rule_2 = { test: () => false }; | ||
const rule_3 = { test: () => false }; | ||
const res = runLazyRules([rule_1, rule_2, rule_3], 'some_value'); | ||
expect(res).toBe(false); | ||
}); | ||
}); | ||
}); |