Instantly share code, notes, and snippets.

Embed
What would you like to do?
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