Last active
April 16, 2019 09:44
-
-
Save bag-man/ddd0096552df17ed109616dba35691af to your computer and use it in GitHub Desktop.
1 + 1 = 2 testing antipattern
This file contains hidden or 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
// 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