From 21d93a5893241957d05d7bb6579d10592e3812e9 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 26 Feb 2019 21:13:11 +0100 Subject: [PATCH] fix and test initialValues for map --- src/observable/map/ObservableMap.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/observable/map/ObservableMap.js b/src/observable/map/ObservableMap.js index 3861974b..cd864ef4 100644 --- a/src/observable/map/ObservableMap.js +++ b/src/observable/map/ObservableMap.js @@ -1,9 +1,8 @@ import BaseObservableMap from "./BaseObservableMap.js"; export default class ObservableMap extends BaseObservableMap { - constructor(keyFn, initialValues) { + constructor(initialValues) { super(); - this._keyFn = keyFn; this._values = new Map(initialValues); } @@ -60,6 +59,16 @@ export default class ObservableMap extends BaseObservableMap { //#ifdef TESTS export function tests() { return { + test_initial_values(assert) { + const map = new ObservableMap([ + ["a", 5], + ["b", 10] + ]); + assert.equal(map.size, 2); + assert.equal(map.get("a"), 5); + assert.equal(map.get("b"), 10); + }, + test_add(assert) { let fired = 0; const map = new ObservableMap(); @@ -95,7 +104,7 @@ export function tests() { test_update_unknown(assert) { let fired = 0; - const map = new ObservableMap(v => v.id); + const map = new ObservableMap(); map.subscribe({ onUpdate() { fired += 1; } });