Skip to content

Commit

Permalink
Add a test to ensure a HasManyReference returns a value when the arra…
Browse files Browse the repository at this point in the history
…y is empty
  • Loading branch information
bmac committed Mar 28, 2017
1 parent dcc92ee commit 9195288
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/integration/references/has-many-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,52 @@ test("value() returns the referenced records when all records are loaded", funct
});
});

test("value() returns an empty array when the reference is loaded and empty", function(assert) {
var family;
run(function() {
family = env.store.push({
data: {
type: 'family',
id: 1,
relationships: {
persons: {
data: []
}
}
}
});
});

run(function() {
var personsReference = family.hasMany('persons');
var records = personsReference.value();
assert.equal(get(records, 'length'), 0);
});
});

test("_isLoaded() returns an true array when the reference is loaded and empty", function(assert) {
var family;
run(function() {
family = env.store.push({
data: {
type: 'family',
id: 1,
relationships: {
persons: {
data: []
}
}
}
});
});

run(function() {
var personsReference = family.hasMany('persons');
var isLoaded = personsReference._isLoaded();
assert.equal(isLoaded, true);
});
});

test("load() fetches the referenced records", function(assert) {
var done = assert.async();

Expand Down

0 comments on commit 9195288

Please sign in to comment.