This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
The example provided for unit testing component bindings is misleading #15968
Closed
Description
I'm submitting a ...
- bug report
- feature request
- other (documentation)
Current behavior:
https://docs.angularjs.org/guide/component#unit-testing-component-controllers
describe('component: heroDetail', function() {
var $componentController;
beforeEach(module('heroApp'));
beforeEach(inject(function(_$componentController_) {
$componentController = _$componentController_;
}));
it('should expose a `hero` object', function() {
// Here we are passing actual bindings to the component
var bindings = {hero: {name: 'Wolverine'}};
var ctrl = $componentController('heroDetail', null, bindings);
expect(ctrl.hero).toBeDefined();
expect(ctrl.hero.name).toBe('Wolverine');
});
});
Expected / new behavior:
The unit test provided as an example is misleading. It makes me believe that we are validating that a binding 'hero' has been defined in the 'heroDetail' component controller. Actually this test only verify that whatever you provide to $componentController you will get it as an attribute of it and that is it. So basically we are testing $componentController rather than the 'heroDetail' component bindings...
If one would like to really test its component bindings he should use $compile.
Angular version: 1.6.5-build.5353+sha.136a42a snapshot