forked from Polymer/polymer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.html
90 lines (90 loc) · 2.9 KB
/
logging.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!doctype html>
<!--
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="utf-8">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../polymer.html">
</head>
<body>
<dom-module id="x-logging">
<script>
HTMLImports.whenReady(() => {
Polymer({
is: 'x-logging',
properties: {
stream: {
value: () => [],
type: Array
}
},
_logger(level, args) {
this.stream.push({level, args});
}
});
});
</script>
</dom-module>
<script>
HTMLImports.whenReady(() => {
class XMixin extends Polymer.LegacyElementMixin(HTMLElement) {
static get is() { return 'x-mixin' }
static get properties() {
return {
stream: {
value: () => [],
type: Array
}
}
}
_logger(level, args) {
this.stream.push({level, args});
}
}
customElements.define(XMixin.is, XMixin);
});
</script>
<script>
suite('Logging', () => {
let fnEl, classEl;
suiteSetup(() => {
fnEl = document.createElement('x-logging');
document.body.appendChild(fnEl);
classEl = document.createElement('x-mixin');
document.body.appendChild(classEl);
});
test('API', () => {
['_log', '_warn', '_error', '_logf', '_logger'].forEach((n) => {
assert.isFunction(fnEl[n], `${n} not defined on Polymer() element`);
assert.isFunction(classEl[n], `${n} not defined on Polymer.Element element`);
});
});
test('_log, _warn_, and _error go through _logger', () => {
fnEl._log('fn');
classEl._log('class');
fnEl._warn('fn');
classEl._warn('class');
fnEl._error('fn');
classEl._error('class');
assert.deepEqual(fnEl.stream, [{level: 'log', args: ['fn']}, {level: 'warn', args: ['fn']}, {level: 'error', args: ['fn']}]);
assert.deepEqual(classEl.stream, [{level: 'log', args: ['class']}, {level: 'warn', args: ['class']}, {level: 'error', args: ['class']}]);
});
test('_logf', () => {
let args = ['hi', 'there'];
let output = fnEl._logf(...args);
assert.oneOf(fnEl.is, output, `${fnEl.is} should be in ${output}`);
assert.includeMembers(output, args, `${args} should be in ${output}`);
});
});
</script>
</body>
</html>