Skip to content

Commit 26e3138

Browse files
committed
failing test-ish for #449
1 parent 4f284fc commit 26e3138

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

can/map/define-map-test.js

+64-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ var set = require("can-set-legacy");
22
var $ = require("jquery");
33
var Map = require("can-define/map/map");
44
var List = require("can-define/list/list");
5-
5+
var DefineMap = Map;
6+
var DefineList = List;
67

78
// load connections
89
var constructor = require("../../constructor/constructor");
@@ -240,3 +241,65 @@ QUnit.asyncTest("instances bound before create are moved to instance store (#296
240241

241242

242243
});
244+
245+
246+
var queues = require("can-queues");
247+
QUnit.test("recompute getList (#449)", function(assert){
248+
const Person = DefineMap.extend("Person",{
249+
name: "string"
250+
});
251+
252+
const People = DefineList.extend("People", {
253+
"#": Person
254+
});
255+
256+
const Todo = DefineMap.extend("Todo",{
257+
id: {type: "number", identity: true},
258+
name: "string",
259+
assignedTo: People
260+
});
261+
262+
Todo.List = DefineList.extend({
263+
"#": Todo,
264+
get mappedList() {
265+
return this.map(({id, name, assignedTo}) => ({id, name, numberOfPeople: assignedTo.length}));
266+
}
267+
});
268+
269+
fixture("GET /api/todos", [
270+
{ name: "mow lawn", id: 5, assignedTo: [{ name:"john"}]},
271+
{ name: "learn canjs", id: 6, assignedTo: [{ name:"john"}, { name:"jane"}]},
272+
]);
273+
274+
fixture.delay = 200;
275+
276+
connect([
277+
constructor,
278+
canMap,
279+
constructorStore,
280+
dataCallbacks,
281+
callbacksCache,
282+
combineRequests,
283+
dataParse,
284+
dataUrl,
285+
realTime],
286+
{
287+
url: "/api/todos",
288+
Map: Todo,
289+
List: Todo.List
290+
});
291+
292+
const done = assert.async();
293+
Todo.getList().then(firstResult => {
294+
firstResult.on("mappedList", function todosChanged(ev, newVal, oldVal){
295+
assert.notOk(true, "call not expected");
296+
queues.logStack();
297+
});
298+
299+
Todo.getList().then(secondResult => {
300+
assert.equal(secondResult, firstResult, "Is the same todos list");
301+
done();
302+
});
303+
});
304+
305+
});

0 commit comments

Comments
 (0)