|
23 | 23 | </head> |
24 | 24 | <body> |
25 | 25 | <script> |
26 | | -(function() { |
| 26 | +suite('Polymer.Base', function() { |
27 | 27 |
|
28 | 28 | var Child; |
29 | 29 | var instance; |
|
139 | 139 |
|
140 | 140 | }); |
141 | 141 |
|
142 | | -})(); |
| 142 | +suite('Logging', function() { |
| 143 | + var logStub; |
| 144 | + setup(function() { |
| 145 | + logStub = sinon.stub(console, 'log'); |
| 146 | + }); |
| 147 | + teardown(function() { |
| 148 | + logStub.restore(); |
| 149 | + }); |
| 150 | + |
| 151 | + test('logger is an entry point for console', function() { |
| 152 | + Polymer.Base._logger('log', ['hi']); |
| 153 | + assert.equal(logStub.callCount, 1); |
| 154 | + }); |
| 155 | + |
| 156 | + test('only allow logging methods', function() { |
| 157 | + var warnStub = sinon.stub(console, 'warn'); |
| 158 | + var errorStub = sinon.stub(console, 'error'); |
| 159 | + var tableStub = sinon.stub(console, 'table'); |
| 160 | + var args = ['hi']; |
| 161 | + Polymer.Base._logger('warn', args); |
| 162 | + Polymer.Base._logger('error', args); |
| 163 | + Polymer.Base._logger('table', args); |
| 164 | + warnStub.restore(); |
| 165 | + errorStub.restore(); |
| 166 | + tableStub.restore(); |
| 167 | + assert.equal(warnStub.callCount, 1); |
| 168 | + assert.equal(errorStub.callCount, 1); |
| 169 | + assert.equal(tableStub.callCount, 0); |
| 170 | + }); |
| 171 | + |
| 172 | + test('logging methods accept strings or an array', function() { |
| 173 | + var expected = ['hello', 'world']; |
| 174 | + Polymer.Base._log('hello', 'world'); |
| 175 | + assert.deepEqual(logStub.args[0], expected, 'strings'); |
| 176 | + Polymer.Base._log(['hello', 'world']); |
| 177 | + assert.deepEqual(logStub.args[1], expected, 'array'); |
| 178 | + }); |
| 179 | + |
| 180 | + test('logf will print the element name and function', function() { |
| 181 | + Child.created = function() { |
| 182 | + this._log(this._logf('ready', 'ready now!')); |
| 183 | + } |
| 184 | + instance.createdCallback(); |
| 185 | + assert.equal(logStub.callCount, 1); |
| 186 | + var expected = Polymer.Base._logPrefix.concat([ |
| 187 | + 'x-child', |
| 188 | + 'ready', |
| 189 | + 'ready now!' |
| 190 | + ]); |
| 191 | + assert.deepEqual(logStub.args[0], expected); |
| 192 | + }); |
| 193 | +}); |
| 194 | +}); |
143 | 195 | </script> |
144 | 196 | </body> |
145 | 197 | </html> |
0 commit comments