Skip to content

Commit

Permalink
Adds a test for #5167
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Mar 17, 2018
1 parent 1fcc54f commit 5cf7d25
Showing 1 changed file with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { run } from '@ember/runloop';
import { watchProperties } from '../../helpers/watch-property';
import { createStore } from 'dummy/tests/helpers/store';

import { module, test } from 'qunit';

import DS from 'ember-data';
import { get } from '@ember/object';
import { watchProperties } from '../../helpers/watch-property';

let store;

Expand Down Expand Up @@ -201,3 +200,65 @@ test('immediately peeking after unloading newly created records works as expecte
'RecordArray state when a new record is unloaded'
);
});

test('unloadAll followed by peekAll in the same run-loop works as expected', function(assert) {
let peekedRecordArray = run(() => store.peekAll('person'));
let watcher = watchProperties(peekedRecordArray, ['length', '[]']);

run(() => {
store.push({
data: [
{
type: 'person',
id: '1',
attributes: {
name: 'John'
}
},
{
type: 'person',
id: '2',
attributes: {
name: 'Joe'
}
}
]
});
});

run(() => {
store.peekAll('person');

assert.watchedPropertyCounts(
watcher,
{ length: 1, '[]': 1 },
'RecordArray state after a single push with multiple records to add'
);

store.unloadAll('person');

assert.watchedPropertyCounts(
watcher,
{ length: 1, '[]': 1 },
'RecordArray state after unloadAll has not changed yet'
);

assert.equal(get(peekedRecordArray, 'length'), 2, 'Array length is unchanged before the next peek');

store.peekAll('person');

assert.equal(get(peekedRecordArray, 'length'), 0, 'We no longer have any array content');

assert.watchedPropertyCounts(
watcher,
{ length: 2, '[]': 2 },
'RecordArray state after a follow up peekAll reflects unload changes'
);
});

assert.watchedPropertyCounts(
watcher,
{ length: 2, '[]': 2 },
'RecordArray state has not changed any further'
);
});

0 comments on commit 5cf7d25

Please sign in to comment.