UNPKG

1.21 kBJavaScriptView Raw
1var assert = require("assert");
2var ExtendedModel = require("../../lib/ExtendedModel.js");
3var ExtendedCollection = require("../../lib/ExtendedCollection.js");
4
5var TestModel = ExtendedModel.extend("TestModel", { id_attribute: "id" });
6var TestCollection = ExtendedCollection.extend("TestCollection", { model: TestModel });
7
8var currentFileMark = ["\t\t\t", "[", __filename, "]", "\n"].join("");
9describe('ExtendedCollection -> fire' + currentFileMark, function(){
10 var collection = new TestCollection();
11 var model_ids = [ 1, 2, 3, 4, 5];
12 var results = new Array(model_ids.length);
13
14 model_ids.forEach(function(id){
15 var model = collection.add({ id: id });
16 model.on("custom_event", function(data){
17 results[id - 1] = { id: id, data: data };
18 });
19 });
20
21 it("collection fires event to all models", function(next){
22 collection.fire( "custom_event", "custom_data" );
23 assert.deepEqual(results, [
24 { id: 1, data: "custom_data" },
25 { id: 2, data: "custom_data" },
26 { id: 3, data: "custom_data" },
27 { id: 4, data: "custom_data" },
28 { id: 5, data: "custom_data" },
29 ]);
30 next();
31 });
32
33});