Created
September 9, 2019 11:08
-
-
Save stevgouws/c0e9f2d42975675e515c03632dd282d5 to your computer and use it in GitHub Desktop.
Decision Table Testing
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
function fieldIsValid({ isRequired, hasError, isEmpty }) { | |
if (hasError) return false; | |
if (isRequired && isEmpty) return false; | |
return true; | |
} | |
describe("fieldIsValid", () => { | |
describe("given it has an error", () => { | |
const permutations = [ | |
{ isRequired: true, hasError: true, isEmpty: true }, | |
{ isRequired: true, hasError: true, isEmpty: false }, | |
{ isRequired: false, hasError: true, isEmpty: true }, | |
{ isRequired: false, hasError: true, isEmpty: true }, | |
{ isRequired: false, hasError: true, isEmpty: false } | |
]; | |
permutations.forEach(permutation => { | |
it(`should return false for values: ${JSON.stringify(permutation)}`, () => { | |
const result = fieldIsValid(...permutations); | |
expect(result).toEqual(false); | |
}); | |
}); | |
}); | |
describe("given it doesn't have an error", () => { | |
it("should return false if it is empty and required", () => { | |
const result = fieldIsValid({ isRequired: true, hasError: false, isEmpty: true }); | |
expect(result).toEqual(false); | |
}); | |
it("should return true if it is not empty and not required", () => { | |
const result = fieldIsValid({ isRequired: false, hasError: false, isEmpty: false }); | |
expect(result).toEqual(true); | |
}); | |
it("should return true if it is empty and not required", () => { | |
const result = fieldIsValid({ isRequired: false, hasError: false, isEmpty: true }); | |
expect(result).toEqual(true); | |
}); | |
it("should return true if it doesn't have errors and is required and not empty", () => { | |
const result = fieldIsValid({ isRequired: true, hasError: false, isEmpty: false }); | |
expect(result).toEqual(true); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment