Skip to content
Browse files

Fix mistaken synchronous code in tests

  • Loading branch information...
1 parent 2bcc767 commit bc720dc02e0b6383c48abcbe8637127a672a2f05 tomhuda committed Mar 11, 2013
View
9 packages/ember-data/tests/integration/find_all_test.js
@@ -33,16 +33,19 @@ test("When all records for a type are requested, the store should call the adapt
invokeAsync(function() {
store.loadMany(type, [{ id: 1, name: "Braaaahm Dale" }]);
- equal(get(allRecords, 'length'), 1, "the record array's length is 1 after a record is loaded into it");
- equal(allRecords.objectAt(0).get('name'), "Braaaahm Dale", "the first item in the record array is Braaaahm Dale");
-
// Only one record array per type should ever be created (identity map)
strictEqual(allRecords, store.all(Person), "the same record array is returned every time all records of a type are requested");
});
};
allRecords = store.find(Person);
+
equal(get(allRecords, 'length'), 0, "the record array's length is zero before any records are loaded");
+
+ Ember.addObserver(allRecords, 'length', function() {
+ equal(get(allRecords, 'length'), 1, "the record array's length is 1 after a record is loaded into it");
+ equal(allRecords.objectAt(0).get('name'), "Braaaahm Dale", "the first item in the record array is Braaaahm Dale");
+ });
});
test("When all records for a type are requested, records that are already loaded should be returned immediately.", function() {
View
12 packages/ember-data/tests/integration/has_many_test.js
@@ -35,7 +35,7 @@ module("Has-Many Relationships", {
});
test("A hasMany relationship has an isLoaded flag that indicates whether the ManyArray has finished loaded", function() {
- expect(9);
+ expect(10);
var array, hasLoaded;
@@ -44,17 +44,17 @@ test("A hasMany relationship has an isLoaded flag that indicates whether the Man
equal(array.get('isLoaded'), false, "Before loading, the array isn't isLoaded");
store.load(type, { id: id });
- if (id === '3') {
- equal(array.get('isLoaded'), true, "After loading all records, the array isLoaded");
- } else {
- equal(array.get('isLoaded'), false, "After loading some records, the array isn't isLoaded");
- }
+ // The isLoaded flag change is deferred, so this should be `false`
+ // even after all of the records have been loaded.
+ // This becoming `true` is tested below in the on('didLoad') event listener.
+ equal(array.get('isLoaded'), false, "After loading some records, the array isn't isLoaded");
}), 1);
};
array = store.findMany(App.Comment, [ 1, 2, 3 ]);
array.on('didLoad', function() {
+ equal(array.get('isLoaded'), true, "After loading all records, the array isLoaded");
ok(true, "didLoad was triggered");
});

0 comments on commit bc720dc

Please sign in to comment.
Something went wrong with that request. Please try again.