锚元素的路径返回undefined在犀牛与env.js [英] Anchor element's pathname returns undefined in Rhino with env.js
问题描述
我遇到了问题的,我相信是植根于实施犀牛锚标记。虽然我使用 env.js ,我怀疑可能是我没有正确配置的东西。
I have run into an issue that I believe is rooted in the implementation of anchor tags in Rhino. Although I am utilizing env.js, I suspect perhaps I am not configuring something correctly.
在特定的,而我试图写对一个angularjs应用程序写入code单元测试时我的问题。当我包括 angular.js
(版本1.2.1 present),我收到以下错误:
In particular, my issue occurs while I am attempting to write unit tests against code written for an angularjs application. When I include angular.js
(versions 1.2.1 to present), I get the following error:
类型错误:无法调用未定义的方法的charAt
我相信错误是<一个结果href=\"https://github.com/angular/angular.js/blob/736c8fbbae57a209f4ba570e38cc3bd0745a9569/src/ng/urlUtils.js#L86\"相对=nofollow>此调用以 urlParsingNode.pathname
因为的console.log
来电显示,在路径
的对象是不确定的。
I am convinced the error is the result of this call to urlParsingNode.pathname
since a console.log
call reveals that the pathname
object is undefined.
我跟踪的 urlParsingNode
来实例化<一个href=\"https://github.com/angular/angular.js/blob/736c8fbbae57a209f4ba570e38cc3bd0745a9569/src/ng/urlUtils.js#L9\"相对=nofollow>这一行的,我们看到它是使用document.createElement(A)的调用的结果;
再往下,我们看到他们设置了的href
属性,<一个href=\"https://github.com/angular/angular.js/blob/736c8fbbae57a209f4ba570e38cc3bd0745a9569/src/ng/urlUtils.js#L75\"相对=nofollow>此行的在希望创建锚标记将利用浏览器能够正确解析URL。
I traced the instantiation of the urlParsingNode
to this line where we see that it is the result of a call to document.createElement("a");
Further down, we see that they set the href
attribute in this line in hopes that the created anchor tag will utilize the browser to correctly parse the URL.
我要相信我不是第一个通过犀牛试图对角JS单元测试,但迄今为止我还没有成功地用Google搜索自己的解决方案。任何提示将大大AP preciated。
I have to believe I'm not the first to attempt JS unit testing for angular via Rhino, but thus far I've not successfully Googled myself to a solution. Any tips will be greatly appreciated.
推荐答案
发现它和固定它。在路径
的getter / setter只需在 env.js $ C未定义
HTMLAnchorElement
$ C>。
Found it and fixed it. The pathname
getter/setter simply was undefined for HTMLAnchorElement
in env.js
.
我提交拉申请,但不幸的是这个项目看起来几乎放弃。我也无法弄清楚如何构建它到一个单一的文件。它的出现也许有人已经采取它在他们自己拆开分解成 require.js
模块。不是一个值得打下去的战役为我的使用案例。
I submitted a pull request, but unfortunately the project looks all but abandoned. I also couldn't figure out how to build it out to a single file. It appears perhaps someone has taken it upon themselves to break it apart into require.js
modules. Not a battle worth fighting for my use case.
因此,对于其他人谁打这个问题,我有code你需要下面。它属于在 HTMLAnchorElement.prototype
。在我的副本 env.js
1.2,这台样机上线8075.我开始在加线8118以下。
So for anyone else who hits this issue, I have the code you need below. It belongs in the HTMLAnchorElement.prototype
. In my copy of env.js
1.2, this prototype begins on line 8075. I added the following at line 8118.
get pathname() {
var uri = Envjs.urlsplit(this.href);
return uri.path;
},
set pathname(val) {
var uri = Envjs.urlsplit(this.href);
uri.path = val
this.href(uri.urlunsplit(uri));
},
仅供参考,我的具体问题与这个拉申请解决。
这篇关于锚元素的路径返回undefined在犀牛与env.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!