-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DOC beta] Assert that both modelName and id are passed to peekRecord
#4998
Conversation
mind adding an expectAssertion test ? |
sure thing |
28c4bde
to
7ed1c47
Compare
Updated. Also added an expectAssertion for the existing assertion that a model name (not a class) must be passed (e.g. when calling |
tests/unit/store/peek-record-test.js
Outdated
}); | ||
}); | ||
|
||
test('peekRecord should assert if passed a model class instead of model name', function(assert) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bantic could you use testInDebug
instead of test
for these tests. The assert gets stripped for the production build and is causing the CI to fail when we run tests in production mode.
import testInDebug from 'dummy/tests/helpers/test-in-debug';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bmac Thanks for pointing that out. I made the change and updated this PR. I'll keep an eye on it to confirm the tests now pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The appveyor tests appear to have passed, but appveyor reports a timeout. Might just need a kick to re-run the tests; afaict everything should be passing now.
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.
7ed1c47
to
42b5bf2
Compare
Thanks a bunch @bantic! |
* commit 'dd3cd69462943530039428a0203f7d66beb1bfd0': Bump master version to 3.0.0-canary Update changelog for Ember Data 2.17.0 release [DOC beta] Assert that both modelName and id are passed to `peekRecord` (emberjs#4998) [doc] Update urlForFindRecord example
So this thing crept up on me today while upgrading from ember-data 2.16 to 3.1. I am not sure if this is correct way to ensure the passing of a 2nd parameter to the method. I have a valid use case where I am fetching the record in an existing component. And the 2nd parameter may be // some-component.js
...
colorId: undefined, // set on the component
fruit: computed('colorId', function() {
// colorId can be null/undefined
return this.get('store').peekRecord('fruit', this.get('colorId'));
}), If you still want to keep the assertion maybe modify the @stefanpenner @bantic Thoughts? |
import { isNone } from '@ember/utils';
colorId: undefined, // set on the component
fruit: computed('colorId', function() {
let colorId = this.get('colorId');
if (!isNone(colorId)) {
return this.get('store').peekRecord('fruit', colorId);
}
return null;
}) I would argue that this is much saner to reason about on what the expected behaviour of that computed property is. |
I've seen folks get confused by forgetting that a modelName is a required param and then do something like
store.peekRecord('my-id')
. This assertion would point out that both values must be passed. Thanks for considering it. :)