Skip to content

Commit

Permalink
feat: enable tag type configuration (#316)
Browse files Browse the repository at this point in the history
* feat: enable tag type configuration

* feat: enable tag type configuration -- added tests
  • Loading branch information
Nouzbe authored and evilebottnawi committed Apr 17, 2018
1 parent 2c3e6b5 commit 892cba5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/addStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ function removeStyleElement (style) {
function createStyleElement (options) {
var style = document.createElement("style");

options.attrs.type = "text/css";
if(options.attrs.type === undefined) {
options.attrs.type = "text/css";
}

addAttrs(style, options.attrs);
insertStyleElement(options, style);
Expand All @@ -212,7 +214,9 @@ function createStyleElement (options) {
function createLinkElement (options) {
var link = document.createElement("link");

options.attrs.type = "text/css";
if(options.attrs.type === undefined) {
options.attrs.type = "text/css";
}
options.attrs.rel = "stylesheet";

addAttrs(link, options.attrs);
Expand Down
42 changes: 42 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,26 @@ describe("basic tests", function() {
runCompilerTest(expected, done);
}); // it attrs

it("type attribute", function(done) {
// Setup
styleLoaderOptions.attrs = {type: 'text/less'};

fs.writeFileSync(
rootDir + "main.js",
[
"var a = require('./style.css');"
].join("\n")
);

// Run
let expected = [
existingStyle,
`<style type="${styleLoaderOptions.attrs.type}">${requiredCss}</style>`
].join("\n");

runCompilerTest(expected, done);
}); // it type attribute

it("url", function(done) {
cssRule.use = [
{
Expand Down Expand Up @@ -261,6 +281,28 @@ describe("basic tests", function() {
runCompilerTest(expected, done);
}); // it url with attrs

it("url with type attribute", function (done) {
cssRule.use = [
{
loader: "style-loader/url",
options: {
attrs: {
type: 'text/less'
}
}
},
"file-loader"
];

// Run
let expected = [
existingStyle,
'<link rel="stylesheet" type="text/less" href="ec9d4f4f24028c3d51bf1e7728e632ff.css">'
].join("\n");

runCompilerTest(expected, done);
}); // it url with type attribute

it("useable", function(done) {
cssRule.use = [
{
Expand Down

0 comments on commit 892cba5

Please sign in to comment.