Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

preAssignBindingsEnabled behavior is not reflected in ngMock $controller #15387

Closed
bathos opened this issue Nov 13, 2016 · 1 comment
Closed

Comments

@bathos
Copy link

bathos commented Nov 13, 2016

Do you want to request a feature or report a bug?

Not sure how this should be classified. I suppose it’s a bug, but it concerns new stuff in RC.

What is the current behavior?

When using ngMock’s decorated $controller service in unit tests, even if preAssignBindingsEnabled is false, $controller(exp, locals, bindings) will try adding bindings old-style, prior to instantiation.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (template: http://plnkr.co/edit/tpl:yBpEi4).

Demonstration with Jasmine test:

http://plnkr.co/edit/IsNy8WjASeKtp6KIpXWt?p=preview

What is the expected behavior?

When preAssignBindingsEnabled is false, I would expect ngMock to honor that.

What is the motivation / use case for changing the behavior?

If ngMock’s decoration doesn’t take into account preAssignBindingsEnabled, one could pretty easily have test results that pass which actually wouldn’t work live. This seems important because if people are converting existing code to work with the new constraints, tests will not currently reveal places where they continue to rely on attribute bindings being available in constructors.

Which versions of Angular, and which browser / OS are affected by this issue? Did this work in previous versions of Angular? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.

6.0.0-rc0

Other information (e.g. stacktraces, related issues, suggestions how to fix)

If I change the test to use native class, it passes. I’m guessing this is because there’s a try-catch in there somewhere that falls back on binding afterwards when forced too. But outside of mocks, when preAssignBindingsEnabled is false, all controller constructors are treated as if they had been defined as ES6 classes, i.e., that they cannot be bound in advance without zany hijinks (e.g. class OneOffChild extends ActualCtrl {}, Object.assign(OneOffChild.prototype, bindings), new OneOffChild(...injections)).

@bathos bathos changed the title preAssignBindingsEnabled behavior is not reflected in ngMock $controller (6.0.0 rc1) preAssignBindingsEnabled behavior is not reflected in ngMock $controller (6.0.0 rc0) Nov 13, 2016
@gkalpak gkalpak added this to the 1.6.0-rc.1 milestone Nov 14, 2016
@gkalpak
Copy link
Member

gkalpak commented Nov 14, 2016

BTW, it might be worth making a similar change in ngMaterial's compiler.

@gkalpak gkalpak changed the title preAssignBindingsEnabled behavior is not reflected in ngMock $controller (6.0.0 rc0) preAssignBindingsEnabled behavior is not reflected in ngMock $controller (1.6.0-rc.0) Nov 15, 2016
@gkalpak gkalpak changed the title preAssignBindingsEnabled behavior is not reflected in ngMock $controller (1.6.0-rc.0) preAssignBindingsEnabled behavior is not reflected in ngMock $controller Nov 15, 2016
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 15, 2016
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 15, 2016
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 15, 2016
gkalpak added a commit that referenced this issue Nov 16, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
ellimist pushed a commit to ellimist/angular.js that referenced this issue Mar 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants