Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Last active November 25, 2015 00:09
Show Gist options
  • Save kentcdodds/1e22dbb029c71bed3a42 to your computer and use it in GitHub Desktop.
Save kentcdodds/1e22dbb029c71bed3a42 to your computer and use it in GitHub Desktop.
ng-nebraska talk files - Filters - The Importance of Learning JavaScript and staying Marketable
export default emojiGetter
function emojiGetter(emojiMap) {
return emojify
function emojify(emojiCode) {
return emojiMap[emojiCode] || emojiMap.confused
}
}
import emojiGetter from './emoji-getter'
import emojiMap from './emoji-map'
const getEmoji = emojiGetter(emojiMap)
describe('emoji-getter', function() {
it('should default to the confused emoji', function() {
expect(emojiFilter()).to.equal('πŸ˜•')
expect(emojiFilter('gibberish')).to.equal('πŸ˜•')
})
it('should return the right emoji for the emoji code', function() {
expect(emojiFilter('cherries')).to.equal('πŸ’')
})
})
import angular from 'angular'
import emojiGetter from './emoji-getter'
import emojiMap from './emoji-map'
angular.module('emojiApp')
.factory('emoji', emojiGetter(emojiMap))
import angular from 'angular'
import emojiGetter from './emoji-getter'
import emojiMap from './emoji-map'
angular.module('emojiApp')
.filter('emoji', () => emojiGetter(emojiMap))
angular.module('emojiApp')
.filter('emoji', emojiFilter)
function emojiFilter(emojiMap) {
return emojify
function emojify(emojiCode) {
return emojiMap[emojiCode] || emojiMap.confused
}
}
describe('emoji filter', function() {
beforeEach(module('emojiApp'))
var emojiFilter
beforeEach(inject($filter) {
emojiFilter = $filter('emoji')
})
it('should default to the confused emoji', function() {
expect(emojiFilter()).to.equal('πŸ˜•')
expect(emojiFilter('gibberish')).to.equal('πŸ˜•')
})
it('should return the right emoji for the emoji code', function() {
expect(emojiFilter('cherries')).to.equal('πŸ’')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment