describe('console', function() { let tool = eruda.get('console') tool.config.set('asyncRender', false) let $tool = $('.eruda-console') let logger = tool._logger function log(i) { return logs()[i].el } function logs() { return logger._displayLogs } beforeEach(function() { eruda.show('console') logger.silentClear() }) it('string', function() { let text = 'This is a log' tool.log(text) expect($(log(0))).toContainText(text) }) it('clear', function() { expect($tool.find('.eruda-logs li')).toHaveLength(0) }) it('recognize url', function() { tool.log('http://liriliri.github.io/eruda/?plugin=fps') expect($(log(0))).toContainHtml( 'http://liriliri.github.io/eruda/?plugin=fps' ) }) it('basic object', function() { let obj = { a: 1 } tool.log(obj) expect($(log(0))).toContainText('Object { a: 1 }') }) it('html', function() { tool.html('Blue') expect($(log(0))).toContainElement('span.color-blue') }) it('timing', function() { tool.time('eruda') tool.timeEnd('eruda') expect($(log(0))).toHaveText(/eruda: [.\d]+ms/) }) it('error', function() { tool.error(new Error('error test')) expect($(log(0))).toContainElement('.eruda-stack') expect($(log(0))).toContainText('error test') }) it('assert', function() { tool.assert(true, 'assert') expect(logs()).toHaveLength(0) tool.assert(false, 'assert') expect(logs()).toHaveLength(1) }) it('count', function() { tool.count('test') tool.count('test') expect($(log(1))).toContainText('test: 2') }) describe('substitution', function() { it('number', function() { tool.log('Eruda is %d', 1.2, 'year old') expect($(log(0))).toContainText('Eruda is 1 year old') logger.silentClear() tool.log('%i', 1.2, 'year old') expect($(log(0))).toContainText('1 year old') logger.silentClear() tool.log('%f', 1.2, 'year old') expect($(log(0))).toContainText('1.2 year old') }) it('string', function() { tool.log('My name is %s', 'eruda') expect($(log(0))).toContainText('My name is eruda') }) it('object', function() { tool.log('Object is %O', { a: 1 }) expect($(log(0))).toContainText('Object is { a: 1 }') logger.silentClear() tool.log('Dom is %o', document.createElement('script')) expect($(log(0))).toContainText('Dom is ') }) it('style', function() { tool.log('%cblue%cgreen', 'color:blue', 'color:green') expect($(log(0))).toContainText( 'bluegreen' ) }) it('Repeat log', function() { for (let i = 0; i < 10; i++) tool.log(1) let $log = $tool.find('.eruda-log-item') expect(logs()).toHaveLength(1) expect($(log(0))).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($(log(0)).find('.eruda-table thead tr')).toContainHtml( '