mirror of
https://github.com/liriliri/eruda.git
synced 2026-03-24 09:48:37 +08:00
Add: Jasmine test
This commit is contained in:
28
test/boot.js
Normal file
28
test/boot.js
Normal file
@@ -0,0 +1,28 @@
|
||||
function boot(name)
|
||||
{
|
||||
// Need a little delay to make sure width and height of webpack dev server iframe are initialized.
|
||||
setTimeout(function ()
|
||||
{
|
||||
eruda.init({tool: name});
|
||||
eruda.show().get().config.set('displaySize', '50%');
|
||||
loadJs('lib/boot', function ()
|
||||
{
|
||||
loadJs('lib/jasmine-jquery', function ()
|
||||
{
|
||||
// This is needed to trigger jasmine initialization.
|
||||
loadJs(name, function ()
|
||||
{
|
||||
window.onload();
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function loadJs(src, cb)
|
||||
{
|
||||
var script = document.createElement('script');
|
||||
script.src = src + '.js';
|
||||
script.onload = cb;
|
||||
document.body.appendChild(script);
|
||||
}
|
||||
16
test/console.html
Normal file
16
test/console.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Console</title>
|
||||
<link rel="stylesheet" href="lib/jasmine.css">
|
||||
<script src="lib/jquery.js"></script>
|
||||
<script src="lib/jasmine.js"></script>
|
||||
<script src="lib/jasmine-html.js"></script>
|
||||
<script src="assets/eruda.js"></script>
|
||||
<script src="boot.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>boot('console');</script>
|
||||
</body>
|
||||
</html>
|
||||
45
test/console.js
Normal file
45
test/console.js
Normal file
@@ -0,0 +1,45 @@
|
||||
var tool = eruda.get('console'),
|
||||
$tool = $('.eruda-console');
|
||||
|
||||
describe('log', function ()
|
||||
{
|
||||
it('string', function ()
|
||||
{
|
||||
var text = 'This is a log';
|
||||
|
||||
tool.clear().log(text);
|
||||
expect($tool.find('.eruda-log')).toContainText(text);
|
||||
});
|
||||
|
||||
it('basic object', function ()
|
||||
{
|
||||
var obj = {a: 1};
|
||||
|
||||
tool.clear().log(obj);
|
||||
expect($tool.find('.eruda-log')).toContainText('Object {"a":1}');
|
||||
});
|
||||
});
|
||||
|
||||
describe('filter', function ()
|
||||
{
|
||||
// Test case from https://github.com/liriliri/eruda/issues/14
|
||||
it('function', function ()
|
||||
{
|
||||
tool.clear().filter(function (log)
|
||||
{
|
||||
return !(log.type === 'error' && /deprecated(.|\n)*stringify/.test(log.src.stack));
|
||||
});
|
||||
|
||||
var obj = {};
|
||||
Object.defineProperty(obj, 'a', {
|
||||
get: function ()
|
||||
{
|
||||
tool.error('deprecated');
|
||||
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
tool.log(obj);
|
||||
expect($tool.find('.eruda-logs li').length).toEqual(1);
|
||||
});
|
||||
});
|
||||
@@ -1,9 +0,0 @@
|
||||
setTimeout(function ()
|
||||
{
|
||||
test();
|
||||
}, 5000);
|
||||
|
||||
function test()
|
||||
{
|
||||
console.log('haha');
|
||||
}
|
||||
@@ -5,10 +5,14 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
<title>Eruda</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script src="effect.js"></script>
|
||||
<script src="assets/eruda.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="test-list">
|
||||
<ul>
|
||||
<li></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="test-element" class="border super-long1 super-long2 super-long-class-name" style="color:red">
|
||||
<!-- This is a comment -->
|
||||
<div class="child-one" style="background-image: url(http://7xn2zy.com1.z0.glb.clouddn.com/blog_elf.jpg); color: rgb(255, 80, 0);">One</div>
|
||||
@@ -73,13 +77,14 @@
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
var el = document.createElement('div');
|
||||
document.body.appendChild(el);
|
||||
setTimeout(function () {
|
||||
eruda.init({container: el});
|
||||
init();
|
||||
eruda.get('console').log('test');
|
||||
}, 1000);
|
||||
(function () {
|
||||
var el = document.createElement('div');
|
||||
document.body.appendChild(el);
|
||||
setTimeout(function ()
|
||||
{
|
||||
eruda.init({container: el});
|
||||
}, 1000);
|
||||
})();
|
||||
</script>
|
||||
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js"></script>
|
||||
<script>FastClick.attach(document.body);</script>-->
|
||||
|
||||
Reference in New Issue
Block a user