From bc4b142e1668fa63ff089fd91b9910f5b22ec9da Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Thu, 16 Jul 2015 17:40:11 -0700 Subject: [PATCH] Add unit tests. --- test/unit/notify-path.html | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/unit/notify-path.html b/test/unit/notify-path.html index 2a0ac95a3e..a89c09171a 100644 --- a/test/unit/notify-path.html +++ b/test/unit/notify-path.html @@ -841,6 +841,66 @@ assert.equal(el.get('nested.again.again.wayOverThere'), 99); }); + test('get array', function() { + el.arrayChanged = function() {}; + el.array = [1, 2, 3]; + el.array.array = [5, 6, 7]; + el.array.prop = 'prop'; + assert.equal(el.get('array'), el.array); + assert.equal(el.get('array.0'), 1); + assert.equal(el.get('array.1'), 2); + assert.equal(el.get('array.2'), 3); + assert.equal(el.get('array.array'), el.array.array); + assert.equal(el.get('array.array.0'), 5); + assert.equal(el.get('array.array.1'), 6); + assert.equal(el.get('array.array.2'), 7); + assert.equal(el.get('array.prop'), 'prop'); + el.unshift('array', 0); + el.splice('array', 2, 0, 1.5); + el.unshift('array.array', 4); + el.splice('array.array', 2, 0, 5.5); + assert.equal(el.get('array.0'), 0); + assert.equal(el.get('array.1'), 1); + assert.equal(el.get('array.2'), 1.5); + assert.equal(el.get('array.3'), 2); + assert.equal(el.get('array.4'), 3); + assert.equal(el.get('array.array.0'), 4); + assert.equal(el.get('array.array.1'), 5); + assert.equal(el.get('array.array.2'), 5.5); + assert.equal(el.get('array.array.3'), 6); + assert.equal(el.get('array.array.4'), 7); + }); + + test('set array', function() { + el.arrayChanged = function() {}; + el.set('array', [1, 2, 3]); + el.set('array.array', [5, 6, 7]); + el.set('array.prop', 'prop'); + assert.equal(el.get('array'), el.array); + assert.equal(el.get('array.0'), 1); + assert.equal(el.get('array.1'), 2); + assert.equal(el.get('array.2'), 3); + assert.equal(el.get('array.array'), el.array.array); + assert.equal(el.get('array.array.0'), 5); + assert.equal(el.get('array.array.1'), 6); + assert.equal(el.get('array.array.2'), 7); + assert.equal(el.get('array.prop'), 'prop'); + el.set(['array', 0], 81); + el.set(['array', 1], 82); + el.set(['array', 2], 83); + el.set(['array.array', 0], 91); + el.set(['array.array', 1], 92); + el.set(['array.array', 2], 93); + el.set('array.prop', 'foo'); + assert.equal(el.get('array.0'), 81); + assert.equal(el.get('array.1'), 82); + assert.equal(el.get('array.2'), 83); + assert.equal(el.get('array.array.0'), 91); + assert.equal(el.get('array.array.1'), 92); + assert.equal(el.get('array.array.2'), 93); + assert.equal(el.get('array.prop'), 'foo'); + }); + });