Open DorianGrey opened 6 years ago
Might be a stencil issue, not sure. Leaving open as I don't have a solution but would like others to chim in
Any updates? I'm also facing the same issue for the latest version.
"@stencil/core": "^1.1.2",
"@stencil/redux": "^0.1.1",
"@stencil/router": "^1.0.1",
This worked for me:
add import '@stencil/redux'; to your root app.tsx file.
PR to add into the docs: https://github.com/ionic-team/stencil-redux/pull/45
@DorianGrey Anyone found a solution to this? @mlynch I'm still not really sure the official replacement for @Prop({ context: 'store' }) store: Store;
has been published in the Stencil docs? That might at least provide a starting point for finding a solution?
@DorianGrey @joewoodhouse @mlynch @boradakash
After facing this store mocking issue for past few days finally found something to inject mock store into components during unit tests.
With the new Stencil testing utility newSpecPage()
(instead of using old TestWindow()
) you can pass an optional, undocumented (and deprecated) argument "context"
with mock store in it.
This way the component receives the mock store before componentWillLoad
is executed.
const page = await newSpecPage({
components: [MyApp],
html: "<my-app></my-app>",
context: {
store: mockStore,
},
});
await page.waitForChanges();
page.flushQueue();
Hi there,
I've recently played a bit with stenciljs and tried to integrate
redux
using this connector. While everything works (approx.) fine for development und production build, I've faced some problems when trying to unit test components that have theStore
as aProp
trying to connect to it.A simple example is the
my-app
component, which attempts to set up the store: https://github.com/DorianGrey/stencil-playground/blob/master/src/components/my-app/my-app.tsxWhen executing the unit test (see https://github.com/DorianGrey/stencil-playground/blob/master/src/components/my-app/my-app.spec.ts) for it, this raises an error like this:
This is obviously raised from the
componentWillLoad
look that attempts to configure the store. I'm not sure why this happens, since everything works fine in the other modes. I might need to somehow inject the store as a property in another way, but I did not find any clue how, especially since this needs to happen beforecomponentWillLoad
is called.The repo can be found here: https://github.com/DorianGrey/stencil-playground
Steps to reproduce
yarn
for installing dependenciesyarn test
will raise errors like mentioned above.Further notes
TypeError: Cannot read property 'queue' of undefined
. This seems to be raised when callingflush
in the unit tests, and no longer occurs when adding a workaround for the store-stuff.store
variable in case it is not defined, but that's somewhat unlikely, esp. when attempting to test a component under more realistic circumstances.Context
object manually as well, however it seems to be absent during the tests.