mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(observable-array): reduce no longer ignores zero as initial value (#6402)
* fix(observable-array): reduce no longer ignores zero as initial value * fix(observable-array): reduceRight now functions properly when initial value is not specified or zero
This commit is contained in:
@@ -646,6 +646,34 @@ export const test_reduce_with_initial_value = function () {
|
||||
TKUnit.assertEqual(result, 11, "ObservableArray reduce function broken when Initial Value is passed.");
|
||||
};
|
||||
|
||||
export const test_reduce_with_zero_as_initial_value = function () {
|
||||
const sa = [{prop: 1}, {prop: 2}, {prop: 3}];
|
||||
let array: ObservableArray<any> = new ObservableArray(sa);
|
||||
const result = array.reduce((a, b) => a + b.prop, 0);
|
||||
TKUnit.assertEqual(result, 6, "ObservableArray reduce function broken when Initial Value is zero.");
|
||||
};
|
||||
|
||||
export const test_reduceRight_isDefined = function () {
|
||||
TKUnit.assert(typeof (array.reduceRight) === "function", "Method 'reduceRight()' should be defined!");
|
||||
};
|
||||
|
||||
export const test_reduceRight_without_initial_value = function () {
|
||||
const sa = [1, 2, 3];
|
||||
let array: ObservableArray<number> = new ObservableArray(sa);
|
||||
const result = array.reduceRight((a, b) => a + b);
|
||||
TKUnit.assertEqual(result, 6, "ObservableArray reduceRight function broken when initialValue is missing");
|
||||
};
|
||||
|
||||
export const test_reduceRight_with_initial_value = function () {
|
||||
const sa = [1, 2, 3];
|
||||
let array: ObservableArray<number> = new ObservableArray(sa);
|
||||
const result = array.reduceRight((a, b) => a + b, 5);
|
||||
TKUnit.assertEqual(result, 11, "ObservableArray reduceRight function broken when Initial Value is passed.");
|
||||
};
|
||||
|
||||
export const test_reduceRight_with_zero_as_initial_value = function () {
|
||||
const sa = [{prop: 1}, {prop: 2}, {prop: 3}];
|
||||
let array: ObservableArray<any> = new ObservableArray(sa);
|
||||
const result = array.reduceRight((a, b) => a + b.prop, 0);
|
||||
TKUnit.assertEqual(result, 6, "ObservableArray reduceRight function broken when Initial Value is zero.");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user