diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2023-09-03 14:35:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-03 14:35:18 +0200 |
commit | 82778b7200a65d6f569da859353c103f8dd2ca2c (patch) | |
tree | 0668d4d6c82ff5e9098c0f23a1cd3d3e0e218716 /spec | |
parent | 2a8b5ea3fb6b3a62ed53d367b6d16d1515422ab9 (diff) | |
parent | bb8b54a3bbe415f1ca6c9fbe917604adb16b53ad (diff) | |
download | svg.js-82778b7200a65d6f569da859353c103f8dd2ca2c.tar.gz svg.js-82778b7200a65d6f569da859353c103f8dd2ca2c.zip |
Merge pull request #1238 from gormster/1237-list-expose-builtin-array-methods
Allow access to original Array.prototype methods on List prefixed with $
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/types/List.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/spec/types/List.js b/spec/spec/types/List.js index a6cab09..35c3886 100644 --- a/spec/spec/types/List.js +++ b/spec/spec/types/List.js @@ -73,6 +73,35 @@ describe('List.js', () => { delete List.prototype.fooBar }) + it('keeps Array prototype names prefixed with $', () => { + // We're picking a function that we know isn't part of core svg.js + // If we implement an 'unshift' function at some point, change this to something else + if (List.prototype.hasOwnProperty('unshift')) { + fail('List.unshift is already a function - change this test to use a different name!'); + return; + } + + List.extend([ 'unshift' ]) + expect(new List().unshift).toEqual(any(Function)) + expect(new List().$unshift).toEqual(Array.prototype.unshift) + + // Check that it works! + const sourceArray = [ + { 'unshift': () => 1 }, + { 'unshift': () => 2 }, + { 'unshift': () => 3 } + ]; + const list = new List(sourceArray) + + expect(list).toEqual(sourceArray) + expect(list.unshift(0)).toEqual([1,2,3]) + + expect(list.$unshift(0)).toEqual(4) + expect(list).toEqual([0].concat(sourceArray)) + + delete List.prototype.unshift; + }); + it('skips reserved names', () => { const { constructor, each, toArray } = List.prototype List.extend(['constructor', 'each', 'toArray']) |