bug: Unexpected behavior with spec test executing code after test statement #4053
Closed
3 tasks done
Labels
Bug: Validated
This PR or Issue is verified to be a bug within Stencil
Prerequisites
Stencil Version
v3.0.0
Current Behavior
When a component has a
setTimeout
constructed in theconnectedCallback
, that is later cleared in thedisconnectedCallback
; writing a spec test for that component will lead to code executing after the test has completed. This results in different errors.Using a log statement will provide:
Depending on the complexity of the code, you can either receive an error pointing to the problematic code:
or you may receive an error for the
$instanceValues$
:This occurs in the Ionic Framework, with the
ion-picker-column
component (observed here: ionic-team/ionic-framework#26749). In that PR, I had to split the test criteria into two separate files, to workaround the issue. The provided repository below is a slimmed down example of what theion-picker-column
component is doing.Expected Behavior
When a test has finished, the component should be "disconnected"/torn down and no code should continue to execute.
System Info
Steps to Reproduce
npm run build
npm run test -- --no-build
my-component-a.spec.tsx
passes, with an errormy-component-b.spec.tsx
does not runmy-component.spec.tsx
runs, but throws an exceptionmy-component-a.spec.tsx
, comment in line 23, which manually calls thedisconnectedCallback
(after the test has performed its expect statement)npm run test -- --no-build
my-component-a.spec.tsx
passes, without an errormy-component-b.spec.tsx
passes, with an errormy-component-spec.tsx
runs, but throws an exceptionmy-component-a.spec.tsx
andmy-component-b.spec.tsx
perform the same test.my-component-spec.tsx
is an example of how the error changes when you have two tests in a single file (multipleit
statements).Code Reproduction URL
https://github.com/sean-perkins/stencil-jest-instance-value
Additional Information
I am unsure if it is the responsibility of the component author to manually invoke the
disconnectedCallback
after the test. Please advise if this is an implementation issue or if Stencil should be tearing down the component in this scenario.The text was updated successfully, but these errors were encountered: