PrintSample.js
function printSample() {
window.print();
}
PrintSample_test.js
describe('PrintSampleテスト > ', function(){
describe('printSampleテスト > ', function(){
beforeEach(function(){
sinon.stub(window, "print");
});
it('モックテスト', function(){
console.log('printSample');
printSample();
console.log('printSample');
});
});
});
PromiseSample.js
function testPromise(url) {
return new Promise (function (resolve, reject) {
var img = document.getElementById("testImg");
img.src = url;
img.border = 1;
img.width = 100;
img.height = 100;
img.hspace = 10;
img.vspace = 10;
img.onload = function() {
console.log('読み込み完了');
}
img.onerror = function() {
console.log('画像を読み込めない!');
}
});
}
PromiseSample_test.js
describe('PromiseSampleテスト', function(){
describe('testPromiseテスト', function(){
var timeout;
beforeEach(function(done) {
timeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
var img = document.createElement("img");
img.id = 'testImg';
document.body.appendChild(img);
done();
});
afterEach(function(){
jasmine.DEFAULT_TIMEOUT_INTERVAL = timeout;
});
it ('loadパターン', function(done){
setTimeout(function(){
testPromise('/okImage');
done();
}, 1000);
var eleImg = document.getElementById('testImg');
expect(eleImg.width).toBe(28);
});
it ('errorパターン', function(done){
try {
setTimeout(function(){
testPromise('/noimage');
done();
}, 1000);
} catch(e) {
}
var eleImg = document.getElementById('testImg');
expect(eleImg.width).toBe(100);
});
});
});
npm install --save-dev resemblejs
最終更新:2015年12月26日 13:36