Skip to content

Commit

Permalink
[DOC beta] Assert that both modelName and id are passed to `peekRecor…
Browse files Browse the repository at this point in the history
…d` (#4998)

Adds expectAssertion test for the new assertion, as well as an
expectAssertion test for the existing assertion that a model name
(string) must be passed instead of a model class.
(cherry picked from commit 1d68d9a)
  • Loading branch information
bantic authored and bmac committed Nov 19, 2017
1 parent d806319 commit ea4397e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,7 @@ Store = Service.extend({
peekRecord(modelName, id) {
heimdall.increment(peekRecord);
assert(`You need to pass a model name to the store's peekRecord method`, isPresent(modelName));
assert(`You need to pass both a model name and id to the store's peekRecord method`, isPresent(modelName) && isPresent(id));
assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, typeof modelName === 'string');
let normalizedModelName = normalizeModelName(modelName);

Expand Down
19 changes: 19 additions & 0 deletions tests/unit/store/peek-record-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { run } from '@ember/runloop';
import setupStore from 'dummy/tests/helpers/store';
import Ember from 'ember';
import testInDebug from 'dummy/tests/helpers/test-in-debug';

import { module, test } from 'qunit';

Expand Down Expand Up @@ -40,3 +42,20 @@ test('peekRecord should return null if the record is not in the store ', functio
assert.equal(null, store.peekRecord('person', 1), 'peekRecord returns null if the corresponding record is not in the store');
});
});

testInDebug('peekRecord should assert if not passed both model name and id', function(assert) {
run(() => {
assert.expectAssertion(() => {
store.peekRecord('my-id');
}, /You need to pass both a model name and id/);
});
});

testInDebug('peekRecord should assert if passed a model class instead of model name', function(assert) {
run(() => {
assert.expectAssertion(() => {
let modelClass = Ember.Object.extend();
store.peekRecord(modelClass, 'id');
}, /Passing classes to store methods has been removed/);
});
});

0 comments on commit ea4397e

Please sign in to comment.