mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(core): ObservableArray splice with start only (#9159)
This commit is contained in:
47
packages/core/__tests__/observable/observable-array.ts
Normal file
47
packages/core/__tests__/observable/observable-array.ts
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import { ObservableArray } from '@nativescript/core/data/observable-array';
|
||||||
|
import { assert } from 'chai';
|
||||||
|
|
||||||
|
describe('observable-array', () => {
|
||||||
|
describe('splice', () => {
|
||||||
|
it('removes an item', () => {
|
||||||
|
const _array = new ObservableArray();
|
||||||
|
|
||||||
|
_array.push(1);
|
||||||
|
_array.push(2);
|
||||||
|
|
||||||
|
_array.splice(0, 1);
|
||||||
|
|
||||||
|
assert.equal(2, _array.getItem(0));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('replaces an item', () => {
|
||||||
|
const _array = new ObservableArray();
|
||||||
|
|
||||||
|
_array.push(1);
|
||||||
|
_array.push(2);
|
||||||
|
|
||||||
|
_array.splice(0, 1, 3);
|
||||||
|
|
||||||
|
assert.equal(3, _array.getItem(0));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('empties on start zero and no delete count', () => {
|
||||||
|
const _array = new ObservableArray();
|
||||||
|
|
||||||
|
_array.push(1);
|
||||||
|
|
||||||
|
_array.splice(0);
|
||||||
|
assert.equal(0, _array.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('empties on length set to zero', () => {
|
||||||
|
const _array = new ObservableArray();
|
||||||
|
|
||||||
|
_array.push(1);
|
||||||
|
_array.push(2);
|
||||||
|
|
||||||
|
_array.length = 0;
|
||||||
|
assert.equal(0, _array.length);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -246,7 +246,7 @@ export class ObservableArray<T> extends Observable {
|
|||||||
*/
|
*/
|
||||||
splice(start: number, deleteCount?: number, ...items: any): T[] {
|
splice(start: number, deleteCount?: number, ...items: any): T[] {
|
||||||
const length = this._array.length;
|
const length = this._array.length;
|
||||||
const result = this._array.splice(start, deleteCount, ...items);
|
const result = arguments.length === 1 ? this._array.splice(start) : this._array.splice(start, deleteCount, ...items);
|
||||||
|
|
||||||
this.notify(<ChangedData<T>>{
|
this.notify(<ChangedData<T>>{
|
||||||
eventName: CHANGE,
|
eventName: CHANGE,
|
||||||
|
|||||||
Reference in New Issue
Block a user