-
-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ngMocks.findInstance returning false instance #298
Comments
Hi, thank you for the report. I'll try to investigate the issue. |
what you describe, it actually the case when there is no I'll add a fix for it in the next release. |
In your case, I would say, check for a typo of English |
If I change to '.p4' I get TypeError: Cannot read property 'debugElement' of null The flow of the last div on StackBlitz follows the same as locally, up to this point: Here I have locally:
I understand what you mean, the text here on GitHub may have been contaminated by the translator, but I checked and changed my local code and it is without typo. See that ... ... will return all three instances of the directive in the component, not just those present in '.p3'
Then the instance of '.p3' exists. |
Good, thanks for the info. I'm working on fix and will provide a built in a few hours for testing. |
On StackBlitz - click enable ivy and it fails, checking further. |
Hi @parloti, good news. Seems like the fix is here. |
ah, false alarm. Fixing the last part with an array of 3. |
Here we go: ng-mocks.zip |
Thanks, it's working correctly. |
Awesome, tomorrow it will be released. |
fix(#298): better behavior of search functions in normal and ivy mode
v11.6.0 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems. |
Hi @satanTime, I tested this version and it did not visibly affect my tests, they continue to work correctly. |
Hi @parloti, thanks for the feedback! |
A situation like this:
Will give:
And with the function
ngMocks.findInstances
:Will return:
Flow of first instances:
mock-helper.find-instance.ts#L14:: mockHelperFindInstances
mock-helper.find-instances.ts#L25:: nestedCheck
mock-helper.find-instances.ts#L16:: nestedCheck
mock-helper.find-instances.ts#L14:: funcGetFromNode
func.get-from-node.ts#L31:: funcGetFromNodeInjector
func.get-from-node-injector.ts#L11:: result.push
Flow of the last instance:
mock-helper.find-instance.ts#L14:: mockHelperFindInstances
mock-helper.find-instances.ts#L25:: nestedCheck
mock-helper.find-instances.ts#L14:: funcGetFromNode
func.get-from-node.ts#L33:: funcGetFromNodeIvy
func.get-from-node-ivy.ts#L29:: funcGetFromNodeScan
func.get-from-node-scan.ts#L59:: result.push(node)
The problem is apparently happening here (func.get-from-node-scan.ts#L53:: detectGatherFlag), it seems that because for the first divs the others present in the array will change the value of 'gather' to 'false', preventing the instance of the directive from being found with this method.
But for the last div the value of 'gather' will remain 'true' until the first instance of the directive in the component is reached, which will be returned.
I tried to reproduce the problem here (mock-directive), but for some reason at StackBlitz the problem does not occur.
Version:
angular: 11.2.0
ng-mocks: 11.5.0
The text was updated successfully, but these errors were encountered: