gpt4 book ai didi

ruby-on-rails-3 - 如何在 Jasmine 中包含来自 CDN 的 javascript 文件?

转载 作者:行者123 更新时间:2023-12-04 19:11:05 27 4
gpt4 key购买 nike

在 Rails 项目中使用 Jasmine 时,为了保持我的 Jasmine 规范中的依赖项一致,我想像在真实页面上所做的那样从 cdn 中提取 jquery。我尝试在我的 Jasmine.yml 文件中这样做:

helpers:
- http://code.jquery.com/jquery-1.9.1.js

但是,这永远行不通,因为在查看 localhost:8888 的源时,我得到:
<script src="/__spec__/http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>

你如何正确地做到这一点?

最佳答案

https://github.com/pivotal/jasmine-gem/issues/135 中的回答

我写了一个帮助程序来加载外部 javascripts。这不是最好的解决方案(我更喜欢使用配置文件),但它对我有用。

var head = document.getElementsByTagName('head')[0];
var jQueryScript = document.createElement('script');
jQueryScript.setAttribute('type', 'text/javascript');
jQueryScript.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js');
head.appendChild(jQueryScript);

关于ruby-on-rails-3 - 如何在 Jasmine 中包含来自 CDN 的 javascript 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14945111/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com