describe('Component vnAutocomplete', () => { let $element; let controller; let data = {id: 1, name: 'Bruce Wayne'}; beforeEach(angular.mock.module('vnCore', $translateProvider => { $translateProvider.translations('en', {}); })); beforeEach(inject(($compile, $rootScope) => { $element = $compile(``)($rootScope); controller = $element.controller('vnAutocomplete'); })); afterEach(() => { $element.remove(); }); describe('url() setter', () => { it(`should set the url property`, () => { controller.url = '/TestModels'; expect(controller.url).toEqual('/TestModels'); }); }); describe('field() setter/getter', () => { it(`should set the field property`, () => { controller.field = 'id'; expect(controller.field).toEqual('id'); }); }); describe('selection property', () => { beforeEach(() => { controller.field = data.id; }); it(`should set selection finding an existing item in the initialData property`, () => { controller.initialData = data; expect(controller.selection).toEqual(data); }); it(`should set selection finding an existing item in the data property`, () => { controller.data = [data]; expect(controller.selection).toEqual(data); }); it(`should set selection to null when can't find an existing item in the data property`, () => { expect(controller.selection).toEqual(null); }); }); });