diff --git a/README.md b/README.md index f557ffc..5d6a2f1 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,10 @@ Note: Behavior is undefined when `unuse`/`unref` is called more often than `use` #### `insertAt` -By default, the style-loader appends ``, existingStyle = "", + checkValue = '
check
', rootDir = path.resolve(__dirname + "/../") + "/", jsdomHtml = [ "", @@ -21,6 +22,9 @@ describe("basic tests", function() { existingStyle, "", "", + "
", + checkValue, + "
", "", "" ].join("\n"); @@ -83,6 +87,15 @@ describe("basic tests", function() { runCompilerTest(expected, done); }); // it insert at top + it("insert into", function(done) { + let selector = "div.target"; + styleLoaderOptions.insertInto = selector; + + let expected = [checkValue, requiredStyle].join("\n"); + + runCompilerTest(expected, done, undefined, selector); + }); // it insert into + it("singleton", function(done) { // Setup styleLoaderOptions.singleton = true; @@ -218,4 +231,4 @@ describe("basic tests", function() { runCompilerTest(expected, done, function() { return this.css.locals.className; }); }); // it local scope -}); // describe \ No newline at end of file +}); // describe diff --git a/test/utils.js b/test/utils.js index 9bab4b6..e7bd05e 100644 --- a/test/utils.js +++ b/test/utils.js @@ -57,7 +57,8 @@ module.exports = { * @param {function} done - Async callback from Mocha. * @param {function} actual - Executed in the context of jsdom window, should return a string to compare to. */ - runCompilerTest: function(expected, done, actual) { + runCompilerTest: function(expected, done, actual, selector) { + selector = selector || "head" compiler.run(function(err, stats) { if (stats.compilation.errors.length) { throw new Error(stats.compilation.errors); @@ -73,7 +74,7 @@ module.exports = { if (typeof actual === 'function') { assert.equal(actual.apply(window), expected); } else { - assert.equal(window.document.head.innerHTML.trim(), expected); + assert.equal(window.document.querySelector(selector).innerHTML.trim(), expected); } // free memory associated with the window window.close(); @@ -83,4 +84,4 @@ module.exports = { }); }); } -}; \ No newline at end of file +};