-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Chai 4/Ember 3.0.0-beta.1 error: You attempted to access the firstObject.inspect
property
#16049
Comments
The issue here is that chai@4 is attempting to provide a nice display message for the failing assertion with some custom display logic. To accomplish that they are using a copy/fork of Node's In Node 7+ the recommended way to customize inspection changed from implementing an I believe the correct solution here is to add
Mind sending in a PR (should be a |
👍 |
Running into a similar issue using chai's deep equal however in this case property is I wish I had a better understanding of what |
@Dhaulagiri - The goal of the assertion is to throw an error when folks "touch" descriptors in a way that shouldn't have been possible, but accidentally was. It is a pretty uncommon situation, but prior to implementing emberjs/rfcs#281 (native ES5 getters for CPs) we wanted to ensure that folks were not relying on "using" descriptors directly from the prototype. I think an example will make this much simpler: let Person = Ember.Object.extend({
name: Ember.computed('first', 'last', function() {
return `${this.get('first')} ${this.get('last')}`;
})
});
let person = Person.create({ first: 'Robert', last: 'Jackson' });
// this "worked" (for some definition of worked) in some Ember versions, but should not have
// the descriptor trap is specifically geared towards making this throw a descriptive error
// since they should have used `this.get('name')` or `Ember.get('name')`
person.name.get() |
That makes sense. The reason this has been a bit of a head scratcher is that all of the errors I've come across are not actually in our app code directly but are either in Chai as described above or in a jQuery plugin (I need to dig more into this to see what is actually happening). |
Right, the usage of a Proxy here is somewhat hard to get right actually. While I have had reports of it legitimately catching bugs/errors in test code (where they were accessing a CP like One possible solution here, would be to remove the branch ember.js/packages/ember-metal/lib/properties.js Lines 108 to 123 in 23e5386
And instead just assert when a user accesses one of the known properties that the computed property prototype has, and allow other access to return @chancancode - Thoughts? |
Reopening for now, because even though we landed #16050 which fixes many scenarios, we are still not 100% certain that we have covered all of the cases that @Dhaulagiri was running into. |
@rwjblue I pushed up another sample test that mimics our app code to the sample repo that reproduces the other error I've seen. |
Awesome, thank you! I'll try to dig into it this afternoon... |
This continues to be a game of whack-a-mole. I've added a few exceptions that have been merged in, but as I clean those up I keep hitting new land mines. Another one related to a jquery plugin we are using is:
Adding an exception for that then triggers the same error on |
We are on an old version of jquery but I believe this same line in the latest version is the same line triggering this for us in our app: https://github.com/jquery/jquery/blob/1ea092a54b00aa4d902f4e22ada3854d195d4a18/src/core.js#L159 |
I'm going to use this as motivation to remove the jquery plugin in question since I wanted to do that anyway, but the chai issue I reproduced in this comment still lingers |
@Dhaulagiri - I believe that the recent changes in #16169 should have addressed the remaining issues. I tested your sample repo against the latest beta build which includes those changes, and the tests pass. |
@rwjblue thank you! I'll be sure to test the next release to confirm but it sounds like we should be able to close this out. |
Confirmed all chai-related errors are fixed. Cannot confirm jquery one since I removed that plugin from our codebase, but it looks like others will be able to confirm in some of the linked issues. |
FYI - This fix was just released as part of 3.0.0-beta.4... |
Confirmed...now to figure out where my new test failures are coming from and try to report them 😭 |
Running tests with Chai4 and Ember 3 beta 1, I'm getting the below error
The error seems to stem from the way Chai 4's
.to.contain
logic works in a test like the below:The Chai code that blows up is something like this:
if (value && typeof value.inspect === 'function' &&
I'm not sure how to reproduce this via twiddle, but you clone this repo and run the included test you can see the error. Note that if I drop back to Chai 3 the problem goes away.
The text was updated successfully, but these errors were encountered: