diff --git a/slim.js b/slim.js index 8d9f96c..5c2aeaf 100644 --- a/slim.js +++ b/slim.js @@ -12,9 +12,12 @@ CssModule.waitTimeout = 60; CssModule.prototype.linkExists = function() { var styleSheets = document.styleSheets; + var anchor = document.createElement("a"); + anchor.href = this.address; + var href = anchor.href; for (var i = 0; i < styleSheets.length; ++i) { - if (this.address === styleSheets[i].href) { + if (href === styleSheets[i].href) { return true; } } diff --git a/test/slim.js b/test/slim.js new file mode 100644 index 0000000..0cfa478 --- /dev/null +++ b/test/slim.js @@ -0,0 +1,31 @@ +var slimLoader = require("steal-css/slim"); +var QUnit = require("steal-qunit"); + +QUnit.module("slim"); + +QUnit.test("Only adds links if not already in the page", function(assert){ + var done = assert.async(); + + var config = { + bundles: { + "1": 2 + }, + paths: { + "2": "dist/foo.css" + } + }; + + Promise.all([ + slimLoader(1, config), + slimLoader(1, config) + ]) + .then(function(){ + var ss = document.styleSheets; + var foos = Array.prototype.slice.call(ss).filter(function(link){ + return /foo/.test(link.href); + }); + + assert.equal(foos.length, 1, "There is only 1 link"); + }) + .then(done); +}); diff --git a/test/test.html b/test/test.html index 18e0589..a573c3c 100644 --- a/test/test.html +++ b/test/test.html @@ -2,6 +2,7 @@ <html> <head> <title>steal-css tests</title> + <link rel="stylesheet" href="./dist/foo.css"> </head> <body> diff --git a/test/test.js b/test/test.js index c0d7f47..8a5e20b 100644 --- a/test/test.js +++ b/test/test.js @@ -2,6 +2,7 @@ var QUnit = require("steal-qunit"); var makeIframe = require("./make-iframe"); require("./unit"); +require("./slim"); QUnit.config.testTimeout = 10000;