Last active
September 19, 2018 02:59
-
-
Save snoblenet/54edd228681d34559f63ecf5eeb9dd44 to your computer and use it in GitHub Desktop.
The contract between getPrefix() and prefixWord() is enforced 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 | |
export const getPrefix = (lang) => { | |
if (lang === 'fr') return 'méga'; | |
return 'mega'; | |
}; | |
// utils/prefix_word.js | |
export const prefixWord = (prefixGetter, wordToPrefix) => prefixGetter() + wordToPrefix; | |
// spec/fixtures/prefix_fixtures.js | |
export const prefixFixtures = { | |
en: { args: 'en', result: 'mega' }, | |
fr: { args: 'en', result: 'méga' }, | |
}; | |
// spec/utils/get_prefix_spec.js | |
import getPrefix from '../../utils/get_prefix'; | |
import prefixFixtures from '../fixtures/prefix_fixtures'; | |
const { args, result } = prefixFixtures.en; | |
describe('getPrefix()', => { | |
it('should return mega', () => | |
expect(getPrefix(...args)).to.equal(result)); | |
}); | |
// spec/utils/prefix_word_spec.js | |
import sinon from 'sinon'; | |
import prefixWord from '../../utils/prefix_word'; | |
import prefixFixtures from '../../utils/prefix_fixtures'; | |
const { args, result } = prefixFixtures.en; | |
const getPrefix = sinon.stub().returns(result); | |
describe('prefixWord()', => { | |
it('should call getPrefix with the correct args', () => | |
expect(prefixWord.args).to.deep.equal([args])); | |
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