Skip to content

Instantly share code, notes, and snippets.

@bag-man bag-man/test.ts
Last active Apr 16, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.