|
19 | 19 | <body> |
20 | 20 |
|
21 | 21 | <dom-module id="x-data"> |
| 22 | + <template> |
| 23 | + <div id="child" |
| 24 | + computed-single="[[computeSingle(inlineSingleDep)]]" |
| 25 | + computed-multi="[[computeMulti(inlineMultiDep1, inlineMultiDep2)]]"> |
| 26 | + </div> |
| 27 | + </template> |
22 | 28 | <script> |
23 | 29 | HTMLImports.whenReady(() => { |
24 | 30 | Polymer({ |
25 | 31 | is: 'x-data', |
| 32 | + _legacyUndefinedCheck: true, |
26 | 33 | properties: { |
27 | 34 | singleProp: String, |
28 | 35 | multiProp1: String, |
29 | | - multiProp2: String |
| 36 | + multiProp2: String, |
| 37 | + computedSingleDep: String, |
| 38 | + computedMultiDep1: String, |
| 39 | + computedMultiDep2: String, |
| 40 | + inlineSingleDep: String, |
| 41 | + inlineMultiDep1: String, |
| 42 | + inlineMultiDep2: String, |
| 43 | + computedSingle: { |
| 44 | + computed: 'computeSingle(computedSingleDep)' |
| 45 | + }, |
| 46 | + computedMulti: { |
| 47 | + computed: 'computeMulti(computedMultiDep1, computedMultiDep2)' |
| 48 | + } |
30 | 49 | }, |
31 | | - _legacyUndefinedCheck: true, |
32 | 50 | observers: [ |
33 | 51 | 'staticObserver("staticObserver")', |
34 | 52 | 'singlePropObserver(singleProp)', |
|
39 | 57 | this.singlePropObserver = sinon.spy(); |
40 | 58 | this.multiPropObserver = sinon.spy(); |
41 | 59 | this.staticObserver = sinon.spy(); |
| 60 | + this.computeSingle = sinon.spy((inlineSingleDep) => `[${inlineSingleDep}]`); |
| 61 | + this.computeMulti = sinon.spy((inlineMultiDep1, inlineMultiDep2) => `[${inlineMultiDep1},${inlineMultiDep2}]`); |
42 | 62 | }, |
43 | 63 | throws() { |
44 | 64 | throw new Error('real error'); |
|
72 | 92 | </template> |
73 | 93 | </test-fixture> |
74 | 94 |
|
| 95 | + <test-fixture id="declarative-single-computed"> |
| 96 | + <template> |
| 97 | + <x-data computed-single-dep="a"></x-data> |
| 98 | + </template> |
| 99 | + </test-fixture> |
| 100 | + |
| 101 | + <test-fixture id="declarative-multi-one-computed"> |
| 102 | + <template> |
| 103 | + <x-data computed-multi-dep1="b"></x-data> |
| 104 | + </template> |
| 105 | + </test-fixture> |
| 106 | + |
| 107 | + <test-fixture id="declarative-multi-all-computed"> |
| 108 | + <template> |
| 109 | + <x-data computed-multi-dep1="b" computed-multi-dep2="c"></x-data> |
| 110 | + </template> |
| 111 | + </test-fixture> |
| 112 | + |
| 113 | + <test-fixture id="declarative-single-computed-inline"> |
| 114 | + <template> |
| 115 | + <x-data inline-single-dep="a"></x-data> |
| 116 | + </template> |
| 117 | + </test-fixture> |
| 118 | + |
| 119 | + <test-fixture id="declarative-multi-one-computed-inline"> |
| 120 | + <template> |
| 121 | + <x-data inline-multi-dep1="b"></x-data> |
| 122 | + </template> |
| 123 | + </test-fixture> |
| 124 | + |
| 125 | + <test-fixture id="declarative-multi-all-computed-inline"> |
| 126 | + <template> |
| 127 | + <x-data inline-multi-dep1="b" inline-multi-dep2="c"></x-data> |
| 128 | + </template> |
| 129 | + </test-fixture> |
| 130 | + |
75 | 131 | <script> |
76 | 132 | (function() { |
77 | 133 |
|
|
83 | 139 | callCounts.singlePropObserver || 0, 'singlePropObserver call count wrong'); |
84 | 140 | assert.equal(el.multiPropObserver.callCount, |
85 | 141 | callCounts.multiPropObserver || 0, 'multiPropObserver call count wrong'); |
| 142 | + assert.equal(el.computeSingle.callCount, |
| 143 | + callCounts.computeSingle || 0, 'computeSingle call count wrong'); |
| 144 | + assert.equal(el.computeMulti.callCount, |
| 145 | + callCounts.computeMulti || 0, 'computeMulti call count wrong'); |
86 | 146 | assert.equal(console.warn.callCount, callCounts.warn || 0, |
87 | 147 | 'console.warn call count wrong'); |
88 | 148 | } |
|
103 | 163 | el.parentNode.removeChild(el); |
104 | 164 | }); |
105 | 165 |
|
106 | | - const singleProp = 'a'; |
107 | | - const multiProp1 = 'b'; |
108 | | - const multiProp2 = 'c'; |
| 166 | + const singleProp = 'singleProp'; |
| 167 | + const multiProp1 = 'multiProp1'; |
| 168 | + const multiProp2 = 'multiProp2'; |
| 169 | + const computedSingleDep = 'computedSingleDep'; |
| 170 | + const computedMultiDep1 = 'computedMultiDep1'; |
| 171 | + const computedMultiDep2 = 'computedMultiDep2'; |
| 172 | + const inlineSingleDep = 'inlineSingleDep'; |
| 173 | + const inlineMultiDep1 = 'inlineMultiDep1'; |
| 174 | + const inlineMultiDep2 = 'inlineMultiDep2'; |
109 | 175 |
|
110 | 176 | suite('check disabled', () => { |
111 | 177 | test('no arguments defined', () => { |
|
144 | 210 | el.multiProp2 = undefined; |
145 | 211 | assertEffects({multiPropObserver: 3}); |
146 | 212 | }); |
| 213 | + test('computeSingle argument defined', () => { |
| 214 | + setupElement(false, {computedSingleDep}); |
| 215 | + assertEffects({computeSingle: 1}); |
| 216 | + assert.equal(el.computedSingle, '[computedSingleDep]'); |
| 217 | + }); |
| 218 | + test('one computeMulti argument defined', () => { |
| 219 | + setupElement(false, {computedMultiDep1}); |
| 220 | + assertEffects({computeMulti: 1}); |
| 221 | + assert.equal(el.computedMulti, '[computedMultiDep1,undefined]'); |
| 222 | + }); |
| 223 | + test('all computeMulti argument defined', () => { |
| 224 | + setupElement(false, {computedMultiDep1, computedMultiDep2}); |
| 225 | + assertEffects({computeMulti: 1}); |
| 226 | + assert.equal(el.computedMulti, '[computedMultiDep1,computedMultiDep2]'); |
| 227 | + }); |
| 228 | + test('inline computeSingle argument defined', () => { |
| 229 | + setupElement(false, {inlineSingleDep}); |
| 230 | + assertEffects({computeSingle: 1}); |
| 231 | + assert.equal(el.$.child.computedSingle, '[inlineSingleDep]'); |
| 232 | + }); |
| 233 | + test('one inline computeMulti argument defined', () => { |
| 234 | + setupElement(false, {inlineMultiDep1}); |
| 235 | + assertEffects({computeMulti: 1}); |
| 236 | + assert.equal(el.$.child.computedMulti, '[inlineMultiDep1,undefined]'); |
| 237 | + }); |
| 238 | + test('all inline computeMulti argument defined', () => { |
| 239 | + setupElement(false, {inlineMultiDep1, inlineMultiDep2}); |
| 240 | + assertEffects({computeMulti: 1}); |
| 241 | + assert.equal(el.$.child.computedMulti, '[inlineMultiDep1,inlineMultiDep2]'); |
| 242 | + }); |
147 | 243 | }); |
148 | 244 |
|
149 | 245 | suite('warn', () => { |
|
183 | 279 | el.multiProp2 = undefined; |
184 | 280 | assertEffects({multiPropObserver: 1, warn: 2}); |
185 | 281 | }); |
| 282 | + test('computeSingle argument defined', () => { |
| 283 | + setupElement(true, {computedSingleDep}); |
| 284 | + assertEffects({computeSingle: 1}); |
| 285 | + assert.equal(el.computedSingle, '[computedSingleDep]'); |
| 286 | + }); |
| 287 | + test('one computeMulti argument defined', () => { |
| 288 | + setupElement(true, {computedMultiDep1}); |
| 289 | + assertEffects({warn: 1}); |
| 290 | + assert.equal(el.computedMulti, undefined); |
| 291 | + }); |
| 292 | + test('all computeMulti argument defined', () => { |
| 293 | + setupElement(true, {computedMultiDep1, computedMultiDep2}); |
| 294 | + assertEffects({computeMulti: 1}); |
| 295 | + assert.equal(el.computedMulti, '[computedMultiDep1,computedMultiDep2]'); |
| 296 | + }); |
| 297 | + test('inline computeSingle argument defined', () => { |
| 298 | + setupElement(true, {inlineSingleDep}); |
| 299 | + assertEffects({computeSingle: 1}); |
| 300 | + assert.equal(el.$.child.computedSingle, '[inlineSingleDep]'); |
| 301 | + }); |
| 302 | + test('one inline computeMulti argument defined', () => { |
| 303 | + setupElement(true, {inlineMultiDep1}); |
| 304 | + assertEffects({warn: 1}); |
| 305 | + assert.equal(el.$.child.computedMulti, undefined); |
| 306 | + }); |
| 307 | + test('all inline computeMulti argument defined', () => { |
| 308 | + setupElement(true, {inlineMultiDep1, inlineMultiDep2}); |
| 309 | + assertEffects({computeMulti: 1}); |
| 310 | + assert.equal(el.$.child.computedMulti, '[inlineMultiDep1,inlineMultiDep2]'); |
| 311 | + }); |
186 | 312 | }); |
187 | 313 | }); |
188 | 314 |
|
|
209 | 335 | el = fixture('declarative-multi-all'); |
210 | 336 | assertEffects({multiPropObserver: 1}); |
211 | 337 | }); |
| 338 | + test('computeSingle argument defined', () => { |
| 339 | + el = fixture('declarative-single-computed'); |
| 340 | + assertEffects({computeSingle: 1}); |
| 341 | + assert.equal(el.computedSingle, '[a]'); |
| 342 | + }); |
| 343 | + test('one computeMulti arguments defined', () => { |
| 344 | + el = fixture('declarative-multi-one-computed'); |
| 345 | + assertEffects({computeMulti: 0, warn: 1}); |
| 346 | + assert.equal(el.computedMulti, undefined); |
| 347 | + }); |
| 348 | + test('all computeMulti defined', () => { |
| 349 | + el = fixture('declarative-multi-all-computed'); |
| 350 | + assert.equal(el.computedMulti, '[b,c]'); |
| 351 | + }); |
| 352 | + test('inline computeSingle argument defined', () => { |
| 353 | + el = fixture('declarative-single-computed-inline'); |
| 354 | + assertEffects({computeSingle: 1}); |
| 355 | + assert.equal(el.$.child.computedSingle, '[a]'); |
| 356 | + }); |
| 357 | + test('inline one computeMulti arguments defined', () => { |
| 358 | + el = fixture('declarative-multi-one-computed-inline'); |
| 359 | + assertEffects({computeMulti: 0, warn: 1}); |
| 360 | + assert.equal(el.$.child.computedMulti, undefined); |
| 361 | + }); |
| 362 | + test('inline all computeMulti defined', () => { |
| 363 | + el = fixture('declarative-multi-all-computed-inline'); |
| 364 | + assert.equal(el.$.child.computedMulti, '[b,c]'); |
| 365 | + }); |
212 | 366 | }); |
213 | 367 | }); |
214 | 368 |
|
|
0 commit comments