Last active
September 19, 2018 03:05
-
-
Save snoblenet/1b2073f1aff6499ea1b8a07b4ffd172c to your computer and use it in GitHub Desktop.
The contract between getPrefix() and prefixWord() is violated but this is not detected by the specs
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
// utils/get_prefix.js | |
// Changed the return value type from string to object | |
export const getPrefix = () => ({ en: 'mega', fr: 'méga' }); | |
// utils/prefix_word.js | |
export const prefixWord = (prefixGetter, wordToPrefix) => prefixGetter() + wordToPrefix; | |
// spec/utils/get_prefix.js | |
import getPrefix from '../../utils/get_prefix'; | |
// Updated the test on getPrefix() to pass | |
describe('getPrefix()', => { | |
it('should return a prefix object', => | |
expect(getPrefix).to.equal({ en: 'mega', fr: 'méga' })); | |
}); | |
// spec/utils/prefix_word.js | |
import prefixWord from '../../utils/prefix_word'; | |
// Forgot to update the stub on getPrefix() | |
const getPrefix = sinon.stub().returns('mega'); | |
// The test on prefixWord() still passes but should fail | |
describe('prefixWord()', => { | |
it('should prefix the supplied word', => | |
expect(prefixWord(getPrefix, 'Word')).to.equal('megaWord')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment