mirror of
https://github.com/liriliri/eruda.git
synced 2026-03-20 09:38:37 +08:00
Dev: Use prettier to format code
This commit is contained in:
171
test/console.js
171
test/console.js
@@ -1,64 +1,56 @@
|
||||
describe('console', function ()
|
||||
{
|
||||
describe('console', function() {
|
||||
var tool = eruda.get('console'),
|
||||
$tool = $('.eruda-console');
|
||||
|
||||
beforeEach(function ()
|
||||
{
|
||||
beforeEach(function() {
|
||||
eruda.show('console');
|
||||
tool.clear();
|
||||
});
|
||||
|
||||
it('string', function ()
|
||||
{
|
||||
it('string', function() {
|
||||
var text = '<span>This is a log</span>';
|
||||
|
||||
tool.log(text);
|
||||
expect($tool.find('.eruda-log')).toContainText(text);
|
||||
});
|
||||
|
||||
it('clear', function ()
|
||||
{
|
||||
it('clear', function() {
|
||||
expect($tool.find('.eruda-logs li')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('recognize url', function ()
|
||||
{
|
||||
it('recognize url', function() {
|
||||
tool.log('http://liriliri.github.io/eruda/?plugin=fps');
|
||||
expect($tool.find('.eruda-log')).toContainHtml('<a href="http://liriliri.github.io/eruda/?plugin=fps" target="_blank">http://liriliri.github.io/eruda/?plugin=fps</a>');
|
||||
expect($tool.find('.eruda-log')).toContainHtml(
|
||||
'<a href="http://liriliri.github.io/eruda/?plugin=fps" target="_blank">http://liriliri.github.io/eruda/?plugin=fps</a>'
|
||||
);
|
||||
});
|
||||
|
||||
it('basic object', function ()
|
||||
{
|
||||
var obj = {a: 1};
|
||||
it('basic object', function() {
|
||||
var obj = { a: 1 };
|
||||
|
||||
tool.log(obj);
|
||||
expect($tool.find('.eruda-log')).toContainText('Object { a: 1 }');
|
||||
$tool.find('.eruda-log').click();
|
||||
});
|
||||
|
||||
it('html', function ()
|
||||
{
|
||||
it('html', function() {
|
||||
tool.html('<span class="color-blue">Blue</span>');
|
||||
expect($tool.find('.eruda-html')).toContainElement('span.color-blue');
|
||||
});
|
||||
|
||||
it('timing', function ()
|
||||
{
|
||||
it('timing', function() {
|
||||
tool.time('eruda');
|
||||
tool.timeEnd('eruda');
|
||||
expect($tool.find('.eruda-html')).toHaveText(/eruda: [.\d]+ms/);
|
||||
});
|
||||
|
||||
it('error', function ()
|
||||
{
|
||||
it('error', function() {
|
||||
tool.error(new Error('error test'));
|
||||
expect($tool.find('.eruda-error')).toContainElement('.eruda-stack');
|
||||
expect($tool.find('.eruda-error')).toContainText('error test');
|
||||
});
|
||||
|
||||
it('assert', function ()
|
||||
{
|
||||
it('assert', function() {
|
||||
tool.assert(true, 'assert');
|
||||
expect($tool.find('.eruda-log-item')).toHaveLength(0);
|
||||
|
||||
@@ -66,19 +58,18 @@ describe('console', function ()
|
||||
expect($tool.find('.eruda-error')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('count', function ()
|
||||
{
|
||||
it('count', function() {
|
||||
tool.count('test').clear();
|
||||
tool.count('test');
|
||||
expect($tool.find('.eruda-html')).toContainText('test: 2');
|
||||
});
|
||||
|
||||
describe('substitution', function ()
|
||||
{
|
||||
it('number', function ()
|
||||
{
|
||||
describe('substitution', function() {
|
||||
it('number', function() {
|
||||
tool.log('Eruda is %d', 1.2, 'year old');
|
||||
expect($tool.find('.eruda-log')).toContainText('Eruda is 1 year old');
|
||||
expect($tool.find('.eruda-log')).toContainText(
|
||||
'Eruda is 1 year old'
|
||||
);
|
||||
|
||||
tool.log('%i', 1.2, 'year old');
|
||||
expect($tool.find('.eruda-log')).toContainText('1 year old');
|
||||
@@ -87,29 +78,31 @@ describe('console', function ()
|
||||
expect($tool.find('.eruda-log')).toContainText('1.2 year old');
|
||||
});
|
||||
|
||||
it('string', function ()
|
||||
{
|
||||
it('string', function() {
|
||||
tool.log('My name is %s', 'eruda');
|
||||
expect($tool.find('.eruda-log')).toContainText('My name is eruda');
|
||||
});
|
||||
|
||||
it('object', function ()
|
||||
{
|
||||
tool.log('Object is %O', {a: 1});
|
||||
expect($tool.find('.eruda-log')).toContainText('Object is { a: 1 }');
|
||||
it('object', function() {
|
||||
tool.log('Object is %O', { a: 1 });
|
||||
expect($tool.find('.eruda-log')).toContainText(
|
||||
'Object is { a: 1 }'
|
||||
);
|
||||
|
||||
tool.log('Dom is %o', document.createElement('script'));
|
||||
expect($tool.find('.eruda-log')).toContainText('Dom is <script></script>');
|
||||
expect($tool.find('.eruda-log')).toContainText(
|
||||
'Dom is <script></script>'
|
||||
);
|
||||
});
|
||||
|
||||
it('style', function ()
|
||||
{
|
||||
it('style', function() {
|
||||
tool.log('%cblue%cgreen', 'color:blue', 'color:green');
|
||||
expect($tool.find('.eruda-log')).toContainHtml('<span style="color:blue">blue</span><span style="color:green">green</span>');
|
||||
expect($tool.find('.eruda-log')).toContainHtml(
|
||||
'<span style="color:blue">blue</span><span style="color:green">green</span>'
|
||||
);
|
||||
});
|
||||
|
||||
it('Repeat log', function ()
|
||||
{
|
||||
it('Repeat log', function() {
|
||||
for (var i = 0; i < 10; i++) tool.log(1);
|
||||
var $log = $tool.find('.eruda-log-item');
|
||||
expect($log).toHaveLength(1);
|
||||
@@ -117,48 +110,41 @@ describe('console', function ()
|
||||
});
|
||||
});
|
||||
|
||||
describe('table', function ()
|
||||
{
|
||||
it('wrong args', function ()
|
||||
{
|
||||
describe('table', function() {
|
||||
it('wrong args', function() {
|
||||
tool.table('test');
|
||||
expect($tool.find('.eruda-table')).not.toContainElement('table');
|
||||
});
|
||||
|
||||
it('sort keys', function ()
|
||||
{
|
||||
tool.table([{a: 1}, {d: 2, a: 2}, {c: 1}]);
|
||||
expect($tool.find('.eruda-table thead tr')).toContainHtml('<th>(index)</th><th>a</th><th>c</th><th>d</th>');
|
||||
it('sort keys', function() {
|
||||
tool.table([{ a: 1 }, { d: 2, a: 2 }, { c: 1 }]);
|
||||
expect($tool.find('.eruda-table thead tr')).toContainHtml(
|
||||
'<th>(index)</th><th>a</th><th>c</th><th>d</th>'
|
||||
);
|
||||
});
|
||||
|
||||
it('basic', function ()
|
||||
{
|
||||
tool.table([{test: 1}, {test: 2, test2: 3}]);
|
||||
it('basic', function() {
|
||||
tool.table([{ test: 1 }, { test: 2, test2: 3 }]);
|
||||
expect($tool.find('.eruda-table tbody tr')).toHaveLength(2);
|
||||
expect($tool.find('.eruda-table thead th')).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('filter', function ()
|
||||
{
|
||||
tool.table([{test: 1}, {test: 2, test2: 3}], 'test');
|
||||
it('filter', function() {
|
||||
tool.table([{ test: 1 }, { test: 2, test2: 3 }], 'test');
|
||||
expect($tool.find('.eruda-table thead th')).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('filter', function ()
|
||||
{
|
||||
describe('filter', function() {
|
||||
// Test case from https://github.com/liriliri/eruda/issues/14
|
||||
it('function', function ()
|
||||
{
|
||||
tool.filter(function (log)
|
||||
{
|
||||
it('function', function() {
|
||||
tool.filter(function(log) {
|
||||
return log.type !== 'error';
|
||||
});
|
||||
|
||||
var obj = {};
|
||||
Object.defineProperty(obj, 'a', {
|
||||
get: function ()
|
||||
{
|
||||
get: function() {
|
||||
tool.error('deprecated');
|
||||
|
||||
return 1;
|
||||
@@ -170,9 +156,12 @@ describe('console', function ()
|
||||
tool.filter('all');
|
||||
});
|
||||
|
||||
it('all info error warn log', function ()
|
||||
{
|
||||
tool.log('log').info('info').error('error').warn('warn').debug('debug');
|
||||
it('all info error warn log', function() {
|
||||
tool.log('log')
|
||||
.info('info')
|
||||
.error('error')
|
||||
.warn('warn')
|
||||
.debug('debug');
|
||||
expect($tool.find('.eruda-log-item')).toHaveLength(5);
|
||||
|
||||
tool.filter('info');
|
||||
@@ -194,8 +183,7 @@ describe('console', function ()
|
||||
tool.filter('all');
|
||||
});
|
||||
|
||||
it('regex', function ()
|
||||
{
|
||||
it('regex', function() {
|
||||
tool.log('test').log('test2');
|
||||
expect($tool.find('.eruda-log-item')).toHaveLength(2);
|
||||
|
||||
@@ -207,43 +195,38 @@ describe('console', function ()
|
||||
});
|
||||
});
|
||||
|
||||
describe('config', function ()
|
||||
{
|
||||
describe('config', function() {
|
||||
var config = tool.config;
|
||||
|
||||
it('max number', function ()
|
||||
{
|
||||
it('max number', function() {
|
||||
config.set('maxLogNum', '10');
|
||||
for (var i = 0; i < 20; i++) tool.log(i);
|
||||
expect($tool.find('.eruda-log-item')).toHaveLength(10);
|
||||
});
|
||||
|
||||
it('override console', function ()
|
||||
{
|
||||
it('override console', function() {
|
||||
config.set('overrideConsole', true);
|
||||
console.log('test');
|
||||
expect($tool.find('.eruda-log-item')).toContainText('test');
|
||||
});
|
||||
|
||||
it('display extra info', function ()
|
||||
{
|
||||
it('display extra info', function() {
|
||||
config.set('displayExtraInfo', true);
|
||||
tool.log('test');
|
||||
expect($tool.find('.eruda-logs li')).toContainElement('.eruda-header');
|
||||
expect($tool.find('.eruda-logs li')).toContainElement(
|
||||
'.eruda-header'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ui', function ()
|
||||
{
|
||||
it('clear', function ()
|
||||
{
|
||||
describe('ui', function() {
|
||||
it('clear', function() {
|
||||
tool.log('test');
|
||||
$('.eruda-clear-console').click();
|
||||
expect($tool.find('.eruda-logs li')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('filter', function ()
|
||||
{
|
||||
it('filter', function() {
|
||||
tool.log('test');
|
||||
tool.warn('test');
|
||||
expect($tool.find('.eruda-logs li')).toHaveLength(2);
|
||||
@@ -252,24 +235,20 @@ describe('console', function ()
|
||||
$('.eruda-filter[data-filter="all"]').click();
|
||||
});
|
||||
|
||||
it('help', function ()
|
||||
{
|
||||
it('help', function() {
|
||||
$tool.find('.eruda-help').click();
|
||||
expect($tool.find('.eruda-html')).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('execute', function ()
|
||||
{
|
||||
it('js', function ()
|
||||
{
|
||||
describe('execute', function() {
|
||||
it('js', function() {
|
||||
$tool.find('textarea').val('1+2');
|
||||
$('.eruda-execute').click();
|
||||
expect($tool.find('.eruda-output')).toContainText('3');
|
||||
});
|
||||
|
||||
it('filter', function ()
|
||||
{
|
||||
it('filter', function() {
|
||||
tool.log('test');
|
||||
tool.log('eruda');
|
||||
expect($tool.find('.eruda-logs li')).toHaveLength(2);
|
||||
@@ -279,12 +258,12 @@ describe('console', function ()
|
||||
});
|
||||
});
|
||||
|
||||
describe('events', function ()
|
||||
{
|
||||
it('log', function ()
|
||||
{
|
||||
describe('events', function() {
|
||||
it('log', function() {
|
||||
var sum = 0;
|
||||
function add(num) { sum += num; }
|
||||
function add(num) {
|
||||
sum += num;
|
||||
}
|
||||
tool.on('log', add);
|
||||
tool.log(5);
|
||||
expect(sum).toBe(5);
|
||||
|
||||
Reference in New Issue
Block a user