Skip to content

Instantly share code, notes, and snippets.

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 snoblenet/4a3dc43a50ed72bbfb9762e703487ba6 to your computer and use it in GitHub Desktop.
Save snoblenet/4a3dc43a50ed72bbfb9762e703487ba6 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
// utils/get_prefix.js
// Changed the return value from 'mega' to 'hyper'
export const getPrefix = () => 'hyper';
// utils/prefix_word.js
export const prefixWord = (prefixGetter, wordToPrefix) => prefixGetter() + wordToPrefix;
// spec/utils/get_prefix_spec.js
import getPrefix from '../../utils/get_prefix';
// Updated the test on getPrefix() to pass
describe('getPrefix()', => {
it('should return hyper', =>
expect(getPrefix).to.equal('hyper'));
});
// spec/utils/prefix_word_spec.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