Last active
August 29, 2015 14:16
-
-
Save Bolza/1b18f9e50def8585b43a to your computer and use it in GitHub Desktop.
AngularJS Test: Directive with ngModel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* jshint -W117, -W030 */ | |
describe('LineItemType', function() { | |
var scope, compileDirective, spy; | |
beforeEach(module('app.lineItem', function($provide) { | |
$provide.service('lineItemType', mockData.lineItemTypeService()); | |
})); | |
beforeEach(inject(function($injector) { | |
var $controller = $injector.get('$controller'); | |
var $compile = $injector.get('$compile'); | |
var $rootScope = $injector.get('$rootScope'); | |
scope = $rootScope.$new(); | |
lineItemType = $injector.get('lineItemType'); | |
spy = sinon.spy(lineItemType, 'getAll'); | |
compileDirective = function (html) { | |
var el = $compile(html)(scope); | |
return el; | |
}; | |
})); | |
describe('Directive', function() { | |
it('should be created and populated when dataset arrives from service', function() { | |
var dir = compileDirective('<line-item-type></line-item-type>'); | |
scope.$digest(); // the controller does the call and waits for response | |
var resolvedData = [mockData.getLineItemType(), mockData.getLineItemType()]; | |
lineItemType.$$resolve('getAll', resolvedData); | |
scope.$digest(); // the controller gets the response | |
expect(dir.find('option').length).to.be.equal(2); | |
}); | |
it('should have default values', function() { | |
var dir = compileDirective('<line-item-type></line-item-type>'); | |
scope.$digest(); | |
expect(dir.find('[name=typeWriter]').val()).to.be.equal('default'); | |
}); | |
it('should update model when writing input', function() { | |
var dir = compileDirective('<line-item-type></line-item-type>'); | |
scope.$digest(); | |
var isolated = dir.isolateScope(); | |
isolated.typeForm.typeWriter.$setViewValue('bolza', 'input'); | |
expect(isolated.model.text).to.be.equal('bolza'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment