sbt-jasmine-plugin
sbt-jasmine-plugin copied to clipboard
"Cannot find function querySelector" when testing AngularJS
I get the error below when loading AngularJS. In this case, the file is angular-scenario.js, but the same error happens with angular.js as well, I just don't have the error readily available.
Could not read file: /Users/dsobral/src/byosprov/src/test/webapp/static/js/lib/angular-scenario.js
error was: TypeError: Cannot find function querySelector in object [object HTMLDocument].
We use this plugin with Angular at work without issues, so the good news is I know it can work. I don't recall having dealt with an error like the one you're experiencing, though. Are you able to share the project on github? If not, you may find my lift-ng.g8 template helpful as another reference for setting up this plugin with angular.
That template uses Angular 1.2.16, about one of the last (maybe the last?) that did not require querySelector/querySelectorAll. What version of Angular are you guys using?
Ok, I've looked into this and you have a few moderately not ideal options.
Long story-short for my team is that we have been updating the versions of angular we use for production, but not for unit testing. Probably not the best solution (honestly, I had completely forgotten we had this divergence). You can do that, and thus far it hasn't bit us. Probably just a matter of time.
The real fix could get ugly, but I've done a similar thing before. Based on this stackoverflow question and this AngularJS group thread, the problem likely lies in env.js which provides a brower-like API to rhino. The second link suggests you can hack angular directly to not call querySelector unless it actually exists. But the real fix is hacking env.js. I have done this before. Seeing this may become a recurring issue doesn't make me feel too awesome, tbh. My understanding is that Nashorn likewise does not include a browser API.
Let me know if this is something you feel up to tackling. I'm pretty busy right now, so it will be a while before I get around to doing it myself.
How about getting a newer EnvJS from https://github.com/envjs/env-js?
We can double check but I think it already has the last version available. It hasn't been touched in four years.
On Jul 22, 2015, at 04:18, Daniel Capo Sobral [email protected] wrote:
How about getting a newer EnvJS from https://github.com/envjs/env-js?
— Reply to this email directly or view it on GitHub.
@dcsobral: I think I finally have a viable solution to this problem. See #14