简体   繁体   English

如何在qUnit中为单个测试添加临时css?

[英]How to add temporary css for a single test in qUnit?

I have a component under test that behaves differently based on a current css of the site. 我有一个受测试的组件,根据网站的当前css行为不同。 I would like to add a css for a single test. 我想为单个测试添加一个css。 Is it possible to add it without creating a file, like a temporary css for the test only? 是否可以在不创建文件的情况下添加它,例如仅用于测试的临时css?

Is it possible to add a css code in the qUnit test function? 是否可以在qUnit测试函数中添加css代码?

You can create style node dynamically with desired CSS rule. 您可以使用所需的CSS规则动态创建style节点。

 var tempCSS = document.createElement("style"); tempCSS.type = "text/css"; tempCSS.innerHTML = ".myClass { background-color: red; }"; document.body.appendChild(tempCSS); 
 <div class="myClass">yahoooooooo</div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM