How can you add javascript files from CDN to Jasmine?

When using the Jasmine in Rails project to support dependencies in my Jasmine specifications, I want to pull jquery from cdn, as is done on a real page. I try to do it like this in my Jasmine.yml file:

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

However, this never works, as when viewing the localhost: 8888 source I get:

<script src="/__spec__/http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>

How are you doing this right?

+5
source share
3 answers

as stated at https://github.com/pivotal/jasmine-gem/issues/135

I wrote an assistant to download external javascripts. This is not the best solution (I would prefer to use a configuration file), but it works for me.

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);
+4
source

@emrox answer is correct and works on jasmine 2.0.

2.1.3 . , ( Chutzpah) "http:" CDN. 2.0 .

, , , :

jQueryScript.setAttribute( '', 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js');

, -, 2.0!

+1

Problem 135 has made it possible for you to list the CDN entries in the jasmine.yml file. eg.

src_files:
  - http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js
  - http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js
  - lib/javascript/**/*.js
0
source

All Articles