Javascript loadStyleFixtures不';jasmine测试中的t负载css
背景是,我正试图用javascript创建一个测试,然后使用jasmine进行测试 我希望能够测试页面是否加载了某些css(即恒温器的颜色是否正确),然后对其进行更新。检查颜色是否更新的测试通过,但检查初始颜色是否正确的第一个测试不通过 在控制台中停止测试后,我意识到css样式表没有应用到测试中——尽管它在正常的本地服务器上工作。这让我觉得使用loadStyleFixtures将css放入jasmine中有一些问题 测试如下所示:Javascript loadStyleFixtures不';jasmine测试中的t负载css,javascript,css,jasmine,jasmine-jquery,Javascript,Css,Jasmine,Jasmine Jquery,背景是,我正试图用javascript创建一个测试,然后使用jasmine进行测试 我希望能够测试页面是否加载了某些css(即恒温器的颜色是否正确),然后对其进行更新。检查颜色是否更新的测试通过,但检查初始颜色是否正确的第一个测试不通过 在控制台中停止测试后,我意识到css样式表没有应用到测试中——尽管它在正常的本地服务器上工作。这让我觉得使用loadStyleFixtures将css放入jasmine中有一些问题 测试如下所示: describe('Display', function(){
describe('Display', function(){
beforeEach(function(){
thermostat = new Thermostat();
jasmine.getFixtures().fixturesPath = '.';
loadFixtures('temperature_change.html');
jasmine.getStyleFixtures().fixturesPath = './public/css';
loadStyleFixtures('stylesheet.css');
});
...
it('can start as yellow', function(){
expect($('#temperature').css('color')).toEqual('rgb(255, 255, 0)');
});
body {
background-color: navy;
color: white;
}
#temperature {
color: yellow;
}
样式表如下所示:
describe('Display', function(){
beforeEach(function(){
thermostat = new Thermostat();
jasmine.getFixtures().fixturesPath = '.';
loadFixtures('temperature_change.html');
jasmine.getStyleFixtures().fixturesPath = './public/css';
loadStyleFixtures('stylesheet.css');
});
...
it('can start as yellow', function(){
expect($('#temperature').css('color')).toEqual('rgb(255, 255, 0)');
});
body {
background-color: navy;
color: white;
}
#temperature {
color: yellow;
}
如果将setStyleFixtures('#temperature{color:yellow;}')添加到beforeach函数中,也不起作用。我的补丁是使用jquery在beforeach块中添加css,而不需要css样式表
非常感谢任何帮助
编辑:测试断断续续地通过-不确定该怎么做,除此之外,可能是我的服务器设置或其他方面的问题 最后,问题是我在测试的beforeach块中以错误的顺序添加了fixture和stylefixture 因此,此代码将通过我的测试:
beforeEach(function(){
thermostat = new Thermostat();
jasmine.getStyleFixtures().fixturesPath = './public/css';
loadStyleFixtures('stylesheet.css');
jasmine.getFixtures().fixturesPath = '.';
loadFixtures('temperature_change.html');
});
但这(我的原始代码)不会:
beforeEach(function(){
thermostat = new Thermostat();
jasmine.getFixtures().fixturesPath = '.';
loadFixtures('temperature_change.html');
jasmine.getStyleFixtures().fixturesPath = './public/css';
loadStyleFixtures('stylesheet.css');
});
关于顺序为什么重要,我的想法是,固定装置自己添加到样式表中,然后再次添加样式表。我认为这让Jasmine感到困惑,需要先加载样式表
我认为间歇通过是因为夹具偶尔会缓慢加载,让样式表有时间先加载,但我不确定这一点。这似乎是正确的,我回来更新我的答案,因为我的id中有一个#,lol,这会扰乱我的测试。当逐步处理jasmine jquery代码时,添加样式会将其附加到头部,添加html会将其附加到正文。因此,我相信,如果它们的顺序错误,那么样式将不会应用于新添加的html元素。