Skip to content

Instantly share code, notes, and snippets.

@bag-man
Last active April 16, 2019 09:44
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 bag-man/ddd0096552df17ed109616dba35691af to your computer and use it in GitHub Desktop.
Save bag-man/ddd0096552df17ed109616dba35691af to your computer and use it in GitHub Desktop.
1 + 1 = 2 testing antipattern
// Avoid generating expected results as they are not testing your logic independently
describe('1+1=2 testing antipattern', () => {
describe('add', () => {
const add = (a: number, b: number): number => a + b;
const expected = 1 + 1;
it('should add two numbers', () => {
// This is testing two sets of logic, and doesnt guarantee the correctness of the function
// as the output of expected could also be wrong
expect(add(1, 1)).toEqual(expected);
// This is actually testing that the add function is correct
expect(add(1, 1)).toEqual(2);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment