var tool = eruda.get('console'), $tool = $('.eruda-console'); beforeEach(function () { tool.clear(); }); describe('log', function () { it('string', function () { var text = 'This is a log'; tool.log(text); expect($tool.find('.eruda-log')).toContainText(text); }); it('clear', function () { expect($tool.find('.eruda-log')).toHaveLength(0); }); it('recognize url', function () { tool.log('http://liriliri.github.io/eruda/?plugin=fps'); expect($tool.find('.eruda-log')).toContainHtml('http://liriliri.github.io/eruda/?plugin=fps'); }); it('basic object', function () { var obj = {a: 1}; tool.log(obj); expect($tool.find('.eruda-log')).toContainText('Object { a: 1 }'); }); it('html', function () { tool.html('Blue'); expect($tool.find('.eruda-html')).toContainElement('span.color-blue'); }); it('timing', function () { tool.time('eruda'); tool.timeEnd('eruda'); expect($tool.find('.eruda-html')).toHaveText(/eruda: [.\d]+ms/); }); 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 () { tool.assert(true, 'assert'); expect($tool.find('.eruda-log-item')).toHaveLength(0); tool.assert(false, 'assert'); expect($tool.find('.eruda-error')).toHaveLength(1); }); it('count', function () { tool.count('test').clear(); tool.count('test'); expect($tool.find('.eruda-html')).toContainText('test: 2'); }); }); 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'); tool.log('%i', 1.2, 'year old'); expect($tool.find('.eruda-log')).toContainText('1 year old'); tool.log('%f', 1.2, 'year old'); expect($tool.find('.eruda-log')).toContainText('1.2 year old'); }); 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 }'); tool.log('Dom is %o', document.createElement('script')); expect($tool.find('.eruda-log')).toContainText('Dom is '); }); it('style', function () { tool.log('%cblue%cgreen', 'color:blue', 'color:green'); expect($tool.find('.eruda-log')).toContainHtml('bluegreen'); }); 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); expect($log.find('.eruda-count')).toContainText('10'); }); }); 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('