-
Notifications
You must be signed in to change notification settings - Fork 13
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
bug: Type error when running tests for component with onChange listener #111
Comments
Hello @samshareski! Thanks for filing this issue and for providing a helpful reproduction. I can confirm that the bug you described is happening, and after a bit of investigation I'm not sure what the source of the problem is but I believe there may be a bug in stencil-store's logic w/ the I'm going to label this for further investigation and ingestion into our backlog. Thanks again for reporting! |
@samshareski are you using |
yes |
Do you have a repo with a reproduction of this issue I can take a look into? |
it's linked in the first comment |
the failing tests are in this spec https://github.com/samshareski/store-test-bug/blob/master/src/components/app-profile/app-profile.spec.ts |
I see what's going on. Handlers are never disposed, you need to unregister them in your component. |
@Serabe this version still has the test failures occurring |
Yes. I'll need to investigate then. |
@Serabe I believe this is a bug in stencil itself, so I believe this issue can be closed and cross referenced in stencil: As a workaround, in your spec tests, you can manually call page.rootInstance.disconnectedCallback(); |
Hey @ajgagnon, I tried calling
unfortunatly I get an |
@christophsaile This is probably because you do not have a disconnectedCallback in your component. You need to add this method to your component: private removeListener: any;
componentWillLoad() {
this.removeListener = onChange('clicks', (value) => {
this.something++;
});
}
disconnectedCallback() {
this.removeListener();
} |
Prerequisites
Stencil Store Version
2.0.0
Stencil Version
2.13.0
Current Behavior
When a component has an onChange listener which has a function that manipulates a https://github.com/State property:
when I try to unit test the component I get a type error like:
● app-profile › clicks the button again
The error only occurs if I'm referencing a @State property, if I reference a component method that just logs something, for example, there is no error.
However, this error doesn't happen with the first test in the suite, only subsequent tests. I'm calling store.dispose() before each test.
Expected Behavior
Tests should run without throwing an error and failing.
Steps to Reproduce
Download repo, run
npm install
thennpm run test
OR
Create a component which registers an
onChange
listener that references a@State
variableWrite a unit test suite for the component with at least 2 tests
Run the unit tests
Code Reproduction URL
https://github.com/samshareski/store-test-bug
Additional Information
No response
The text was updated successfully, but these errors were encountered: