Skip to content

Commit 5d6a98d

Browse files
committed
Test insertInto option
1 parent 64abab7 commit 5d6a98d

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

test/basicTest.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ describe("basic tests", function() {
1414
localScopedCss = ":local(.className) { background: red; }",
1515
requiredStyle = `<style type="text/css">${requiredCss}</style>`,
1616
existingStyle = "<style>.existing { color: yellow }</style>",
17+
checkValue = '<div class="check">check</div>',
1718
rootDir = path.resolve(__dirname + "/../") + "/",
1819
jsdomHtml = [
1920
"<html>",
2021
"<head>",
2122
existingStyle,
2223
"</head>",
2324
"<body>",
25+
"<div class='target'>",
26+
checkValue,
27+
"</div>",
2428
"</body>",
2529
"</html>"
2630
].join("\n");
@@ -83,6 +87,15 @@ describe("basic tests", function() {
8387
runCompilerTest(expected, done);
8488
}); // it insert at top
8589

90+
it("insert into", function(done) {
91+
let selector = "div.target";
92+
styleLoaderOptions.insertInto = selector;
93+
94+
let expected = [checkValue, requiredStyle].join("\n");
95+
96+
runCompilerTest(expected, done, undefined, selector);
97+
}); // it insert into
98+
8699
it("singleton", function(done) {
87100
// Setup
88101
styleLoaderOptions.singleton = true;
@@ -218,4 +231,4 @@ describe("basic tests", function() {
218231
runCompilerTest(expected, done, function() { return this.css.locals.className; });
219232
}); // it local scope
220233

221-
}); // describe
234+
}); // describe

test/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = {
5757
* @param {function} done - Async callback from Mocha.
5858
* @param {function} actual - Executed in the context of jsdom window, should return a string to compare to.
5959
*/
60-
runCompilerTest: function(expected, done, actual) {
60+
runCompilerTest: function(expected, done, actual, selector = "head") {
6161
compiler.run(function(err, stats) {
6262
if (stats.compilation.errors.length) {
6363
throw new Error(stats.compilation.errors);
@@ -73,7 +73,7 @@ module.exports = {
7373
if (typeof actual === 'function') {
7474
assert.equal(actual.apply(window), expected);
7575
} else {
76-
assert.equal(window.document.head.innerHTML.trim(), expected);
76+
assert.equal(window.document.querySelector(selector).innerHTML.trim(), expected);
7777
}
7878
// free memory associated with the window
7979
window.close();
@@ -83,4 +83,4 @@ module.exports = {
8383
});
8484
});
8585
}
86-
};
86+
};

0 commit comments

Comments
 (0)