An open API service indexing awesome lists of open source software.

https://github.com/normandy72/testing-components

Testing AngularJS Components. Coursera course "Single Page Web Applications with AngularJS" by Yaakov Chaikin.
https://github.com/normandy72/testing-components

angular angularjs html html5 jasmine jasmine-tests javascript js testing

Last synced: about 1 month ago
JSON representation

Testing AngularJS Components. Coursera course "Single Page Web Applications with AngularJS" by Yaakov Chaikin.

Awesome Lists containing this project

README

        

# Testing AngularJS Components
### beforeEach Setup
```
var $componentController;

beforeEach(module('MyApp'));

beforeEach(inject(function(_$componentController_){
$componentController = _$componentController_;
}));
```
### Test Method
```
it('should update value', function(){
var bindings = {
prop1: {val: 'some val'}
};

var ctrl = $componentController('myComp', {}, bindings);

var updatedVal1 = ctrl.val;

expect(updatedVal).toEqual('some val');
});
```
***
#### _Summary_
Use the following steps to test a component:
* In beforeEach:
* use mock inject function to inject `$componentController` service.
* In the test method:
* set up a bindings object with expected props (if any);
* set up objects controller expects to be injected (if any);
* create controller with `$componentController('componentName', injections, bindings)`.
***