I have the following component:
angular.module('foo')
.component('searchInput', {
bindings: {
text: "<query"
},
templateUrl: 'components/searchInput/searchInput.html',
controller: 'SearchInputCtrl'
});
For the following to pass:
expect(component.text).toBe('bar');
I have to use the following code:
var component = $componentController('searchInput',
{$scope: {}},
{
text: 'bar'
}
);
However, I want to test that the value being bound to 'text' is being sourced from 'query'. This does not work:
var component = $componentController('searchInput',
{$scope: {}},
{
query: 'bar'
}
);
You can test this sort of thing by compiling the component. e.g.
inject(function($compile, $rootScope) {
var parentScope = $rootScope.$new();
parentScope.myVar = 'test';
var element = angular.element('<search-input query="myVar"></search-input>');
var compiledElement = $compile(element)(parentScope);
parentScope.$digest();
var scope = compiledElement.isolateScope();
expect(scope.$ctrl.text).toBe('test');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With