angular-viacep
Version:
Angular Module for integration WebService ViaCep created by César Barone <cesar.bmcosta@gmail.com>
48 lines (35 loc) • 1.4 kB
text/coffeescript
describe 'angular-viacep::viacep', ->
beforeEach ->
module 'angular.viacep'
beforeEach inject (_$compile_, _$rootScope_) ->
= _$compile_
= _$rootScope_
.address = {}
= ('<div via-cep-form></div>')()
.$digest()
beforeEach inject (_viaCepHelper_) ->
= _viaCepHelper_
= .controller('viaCepForm')
it 'should attach empty mappers', ->
expect(.mappers).toEqual []
it 'should call viaCepHelper #isValidKey and throw error for invalid key', ->
spyOn(, 'isValidKey')
expect(() =>
.registerMapper('invalidKey', {})
).toThrow(new Error("viacep key must be one of: cep,logradouro,complemento,bairro,localidade,uf,unidade,ibge,gia"));
it 'should call viaCepHelper #isValidKey', ->
mapper = {mapper: 'm'}
.registerMapper('logradouro', mapper)
expect(.mappers['logradouro']).toBe(mapper)
describe "#get", ->
it 'should call viaCepHelper#get with mappers', ->
cep = '88054611'
spyOn(, 'get')
.get(cep)
expect(.get).toHaveBeenCalledWith(cep, .mappers)
describe "#cleanAddress", ->
it 'should call viaCepHelper#cleanAddress with mappers', ->
spyOn(, 'cleanAddress')
.cleanAddress()
expect(.cleanAddress).toHaveBeenCalled()