Skip to content

Instantly share code, notes, and snippets.

@Cst2989
Last active October 22, 2021 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cst2989/705c83d3a2f1010005fd4594ed43639f to your computer and use it in GitHub Desktop.
Save Cst2989/705c83d3a2f1010005fd4594ed43639f to your computer and use it in GitHub Desktop.
Testing for invalid inputs
describe('bowlingScore error boundaries', () => {
test('it should return error message for too few rolls', () => {
const inputRolls = [1, 2, 3]; // ARRANGE
const gameScore = bowlingScore(inputRolls); // ACT
expect(gameScore).toBe('Invalid rolls input'); // ASSERT
});
test('it should return error message for too many rolls', () => {
const inputRolls = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23,
]; // ARRANGE
const gameScore = bowlingScore(inputRolls); // ACT
expect(gameScore).toBe('Invalid rolls input'); // ASSERT
});
test('it should return error message if negative numbers', () => {
const inputRolls = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, -19, 20,
]; // ARRANGE
const gameScore = bowlingScore(inputRolls); // ACT
expect(gameScore).toBe('Invalid rolls input'); // ASSERT
});
test('it should return error message non-zero number after strike', () => {
const inputRolls = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 10, 2, 20,
];
const gameScore = bowlingScore(inputRolls);
expect(gameScore).toBe(0);
});
test('it should return error message sum in frame is bigger than 10', () => {
const inputRolls = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 10, 2, 20,
];
const gameScore = bowlingScore(inputRolls);
expect(gameScore).toBe(0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment