Skip to content

Instantly share code, notes, and snippets.

@snoblenet
Last active September 19, 2018 03:03
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/b7daa4fc4ede9396e3c8ea6a2f7a6ab6 to your computer and use it in GitHub Desktop.
Save snoblenet/b7daa4fc4ede9396e3c8ea6a2f7a6ab6 to your computer and use it in GitHub Desktop.
The contract between getPrefix() and prefixWord() is respected by the modules but not enforced by the specs
// utils/get_prefix.js
export const getPrefix = () => 'mega';
// utils/prefix_word.js
export const prefixWord = (prefixGetter, wordToPrefix) => prefixGetter() + wordToPrefix;
// spec/utils/get_prefix_spec.js
import getPrefix from '../../utils/get_prefix';
describe('getPrefix()', => {
it('should return mega', () =>
expect(getPrefix).to.equal('mega'));
});
// spec/utils/prefix_word_spec.js
import sinon from 'sinon';
import prefixWord from '../../utils/prefix_word';
const getPrefix = sinon.stub().returns('mega');
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