Skip to content

Commit

Permalink
Document issue #2. Refactor fixture helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Burgmer committed May 2, 2014
1 parent d024c3e commit cfe721c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions test/specs/InlineScriptSpec.js
Expand Up @@ -30,19 +30,21 @@ describe("JS inline", function () {
};

var anExternalScript = function () {
return anExternalScriptWith("url/some.js", "var b = 1;");
return anExternalScriptWith("var b = 1;", "url/some.js");
};

var anotherExternalScript = function () {
var script = anExternalScriptWith("url/someOther.js", "function something() {}");
var script = anExternalScriptWith("function something() {}", "url/someOther.js");
script.type = "text/javascript";
script.id = "myScript";
return script;
};

var anExternalScriptWith = function (url, content) {
var anExternalScriptWith = function (content, url) {
var externalScript = window.document.createElement("script");

url = url || 'some/url.js';

externalScript.src = url;

mockAjaxUrl(url, content);
Expand Down Expand Up @@ -133,11 +135,7 @@ describe("JS inline", function () {
});

it("should correctly quote closing HTML tags in the script", function (done) {
var script = window.document.createElement("script");
script.src = "some_url.js";

mockAjaxUrl("some_url.js", 'var closingScriptTag = "</script>";');
doc.head.appendChild(script);
doc.head.appendChild(anExternalScriptWith('var closingScriptTag = "</script>";'));

inlineScript.inline(doc, {}).then(function () {
expect(doc.head.getElementsByTagName("script")[0].textContent).toEqual('var closingScriptTag = "<\\/script>";');
Expand All @@ -146,6 +144,16 @@ describe("JS inline", function () {
});
});

xit("should not quote a regex", function (done) {
doc.head.appendChild(anExternalScriptWith("/</.test('<');"));

inlineScript.inline(doc, {}).then(function () {
expect(doc.head.getElementsByTagName("script")[0].textContent).toEqual("/</.test('<');");

done();
});
});

it("should respect the document's baseURI when loading linked JS", function (done) {
var getDocumentBaseUrlSpy = spyOn(util, 'getDocumentBaseUrl').and.callThrough();

Expand All @@ -160,7 +168,7 @@ describe("JS inline", function () {
});

it("should respect optional baseUrl when loading linked JS", function (done) {
doc.head.appendChild(anExternalScriptWith('externalScript.js', ''));
doc.head.appendChild(anExternalScriptWith('', 'externalScript.js'));

inlineScript.inline(doc, {baseUrl: "some_base_url/"}).then(function () {
expect(ajaxSpy).toHaveBeenCalledWith('externalScript.js', {baseUrl: "some_base_url/"});
Expand Down

0 comments on commit cfe721c

Please sign in to comment.