describe('Ionic Checkbox', function() { var el, scope, compile; beforeEach(module('ionic')); beforeEach(inject(function($compile, $rootScope) { compile = $compile; scope = $rootScope; })); it('should set the checkbox name', function() { el = compile('')(scope); var input = el.find('input'); expect(input.attr('name')).toEqual('myname'); }); it('should setup checkbox markup', function() { el = compile('INNER TEXT')(scope); expect(el.hasClass('item')).toEqual(true); expect(el.hasClass('item-checkbox')).toEqual(true); var label = el.find('div'); expect(label.hasClass('checkbox')).toEqual(true); var input = el.find('input'); expect(input.attr('type')).toEqual('checkbox'); var div = el.find('div'); expect(div.hasClass('item-content')).toEqual(true); expect(div.text()).toEqual('INNER TEXT'); }); it('should pass down attrs', function() { el = compile('')(scope); scope.$apply(); var input = el.find('input'); expect(input.attr('name')).toBe('name'); expect(input.attr('ng-model')).toBe('model'); expect(input.attr('ng-checked')).toBe('checked'); expect(input.attr('ng-disabled')).toBe('disabled'); expect(input.attr('ng-true-value')).toBe('true-value'); expect(input.attr('ng-false-value')).toBe('false-value'); expect(input.attr('ng-change')).toBe('change'); }); it('should ngChecked properly', function() { el = compile('')(scope); scope.$apply(); var input = el.find('input'); expect(input[0].hasAttribute('checked')).toBe(false); scope.$apply('shouldCheck = true'); expect(input[0].hasAttribute('checked')).toBe(true); scope.$apply('shouldCheck = false'); expect(input[0].hasAttribute('checked')).toBe(false); }); it('should ngChange properly', function() { el = compile('')(scope); scope.change = jasmine.createSpy('change'); scope.$apply(); var input = el.find('input'); var ngModel = input.controller('ngModel'); expect(scope.change).not.toHaveBeenCalled(); ngModel.$setViewValue(true); scope.$apply(); expect(scope.change).toHaveBeenCalledWith(true); scope.change.reset(); ngModel.$setViewValue(false); scope.$apply(); expect(scope.change).toHaveBeenCalledWith(false); }); });