Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.

Make example with Vuex #6

Closed
bahmutov opened this issue Dec 27, 2017 · 4 comments
Closed

Make example with Vuex #6

bahmutov opened this issue Dec 27, 2017 · 4 comments

Comments

@bahmutov
Copy link
Contributor

bahmutov commented Dec 27, 2017

Make example with Vuex that extends Vue and use data store from a component. This looks like a good code example https://github.com/vuejs/vuex/tree/dev/examples/counter

@bahmutov
Copy link
Contributor Author

bahmutov commented Jan 2, 2018

bahmutov added a commit that referenced this issue Jan 2, 2018
@amirrustam
Copy link
Contributor

@bahmutov If you're not still working on this I can take stab it. I noticed the test was failing due the component not getting rendered at all. The issue was with Vuex not being installed on the root Vue instance, and also the test was testing for a non-existent button. Since Vuex is plugin I added it to the options:

import Vuex from 'vuex'

//...

const extensions = {
  plugins: [Vuex],
  components: {
    counter: Counter
  },
}
const template = '<counter />'
beforeEach(mountVue({template, store}, { extensions }))

I confirmed that Cypress.vue.$store exists, and the component renders now. However, {{$store.state.count}} within the template does not update reactively when the state is changed.

I also noticed the currently disabled/undocumented vuex and vuexPath options which could be relevant.

I was just looking at things quickly, but I'll come back and work it on some work when I get the chance, and if you find it helpful.

@bahmutov
Copy link
Contributor Author

Absolutely, @amirrustam take a stab at it. Basically I understand that our problem is loading components in test iframe, but then mounting them in app iframe. I had same issue with RouterLink when using vue-router in these tests https://github.com/bahmutov/vue-hackernews-2.0

See file https://github.com/bahmutov/vue-hackernews-2.0/blob/master/cypress/integration/item-spec.js specifically.

@amirrustam
Copy link
Contributor

@bahmutov We both arrived at the same conclusion (iframes!) here. I'll be happy to look into this, should be interesting.

amirrustam added a commit to amirrustam/cypress-vue-unit-test that referenced this issue Jan 26, 2018
The inner Vue instance within Vuex Store must be refeshed by `resetStoreVM` to restore reactivity of the store state. This doesn’t fix stale mapped getters within components. That’s a separate WIP issue.
amirrustam added a commit to amirrustam/cypress-vue-unit-test that referenced this issue Jan 26, 2018
Current mapped vuex getters within components become stale. To have a working Counter example, the computed mapped `evenOrOdd` is accessed directly via `$store`. This will be changed back once the stale mapped getter issue (WIP) is fixed.
amirrustam added a commit to amirrustam/cypress-vue-unit-test that referenced this issue Jan 26, 2018
Added tests to cover all the features within the component. Fixes cypress-io#6
bahmutov pushed a commit that referenced this issue Jan 28, 2018
* fix: vuex integration (#6)

The inner Vue instance within Vuex Store must be refeshed by `resetStoreVM` to restore reactivity of the store state. This doesn’t fix stale mapped getters within components. That’s a separate WIP issue.

* fix: stale mapped getter `evenOrOdd` (#6)

Current mapped vuex getters within components become stale. To have a working Counter example, the computed mapped `evenOrOdd` is accessed directly via `$store`. This will be changed back once the stale mapped getter issue (WIP) is fixed.

* feat: added example tests for Counter component

Added tests to cover all the features within the component. Fixes #6

* minor: following better practices
amirrustam added a commit to amirrustam/cypress-vue-unit-test that referenced this issue Jan 28, 2018
Refactors how the Vue instance within the component app frame is initialized, and fully fixes Vue integration.
- fixes lingering issues after pull request cypress-io#13
- fully fixes cypress-io#6
- fixes #1
- README docs have been updated to reflect refactoring
- 'vue' option has been deprecated (with warning to user) as it's no longer necessary
- spread operator support has been added for upcoming Vuex example
amirrustam added a commit to amirrustam/cypress-vue-unit-test that referenced this issue Jan 28, 2018
To thoroughly demonstrate Vuex support after the refactoring in commit e8773383, Counter.vue now:
- Utilizes all Vuex mapping functions.
- Can properly use computed mapped getters in its template. This was an issue after cypress-io#13.
- Set count state via an input field to demonstrate mapped mutations. Two tests have been added to the spec for this new input field.

Close cypress-io#6
bahmutov pushed a commit that referenced this issue Jan 31, 2018
* fix: vuex integration (#6)

The inner Vue instance within Vuex Store must be refeshed by `resetStoreVM` to restore reactivity of the store state. This doesn’t fix stale mapped getters within components. That’s a separate WIP issue.

* fix: stale mapped getter `evenOrOdd` (#6)

Current mapped vuex getters within components become stale. To have a working Counter example, the computed mapped `evenOrOdd` is accessed directly via `$store`. This will be changed back once the stale mapped getter issue (WIP) is fixed.

* feat: added example tests for Counter component

Added tests to cover all the features within the component. Fixes #6

* minor: following better practices

* fix: refactor Vue initialization in app frame

Refactors how the Vue instance within the component app frame is initialized, and fully fixes Vue integration.
- fixes lingering issues after pull request #13
- fully fixes #6
- fixes amirrustam#1
- README docs have been updated to reflect refactoring
- 'vue' option has been deprecated (with warning to user) as it's no longer necessary
- spread operator support has been added for upcoming Vuex example

* feat: enhanced Vuex Counter example and test spec

To thoroughly demonstrate Vuex support after the refactoring in commit amirrustam/cypress-vue-unit-test@e8773383, Counter.vue now:
- Utilizes all Vuex mapping functions.
- Can properly use computed mapped getters in its template. This was an issue after #13.
- Set count state via an input field to demonstrate mapped mutations. Two tests have been added to the spec for this new input field.

Close #6

* minor: remove redundant declaration
JessicaSachs pushed a commit to cypress-io/cypress that referenced this issue Sep 29, 2020
* working on Vuex example for cypress-io/cypress-vue-unit-test#6

* fix: Vuex integration and add Counter example tests (cypress-io/cypress-vue-unit-test#13)

* fix: vuex integration (bahmutov/cypress-vue-unit-testbahmutov/cypress-vue-unit-test#6)

The inner Vue instance within Vuex Store must be refeshed by `resetStoreVM` to restore reactivity of the store state. This doesn’t fix stale mapped getters within components. That’s a separate WIP issue.

* fix: stale mapped getter `evenOrOdd` (bahmutov/cypress-vue-unit-testbahmutov/cypress-vue-unit-test#6)

Current mapped vuex getters within components become stale. To have a working Counter example, the computed mapped `evenOrOdd` is accessed directly via `$store`. This will be changed back once the stale mapped getter issue (WIP) is fixed.

* feat: added example tests for Counter component

Added tests to cover all the features within the component. Fixes bahmutov/cypress-vue-unit-testbahmutov/cypress-vue-unit-test#6

* minor: following better practices

* Full Vuex support with enhanced Counter.vue example and test spec (cypress-io/cypress-vue-unit-test#15)

* fix: vuex integration (bahmutov/cypress-vue-unit-testbahmutov/cypress-vue-unit-test#6)

The inner Vue instance within Vuex Store must be refeshed by `resetStoreVM` to restore reactivity of the store state. This doesn’t fix stale mapped getters within components. That’s a separate WIP issue.

* fix: stale mapped getter `evenOrOdd` (bahmutov/cypress-vue-unit-testbahmutov/cypress-vue-unit-test#6)

Current mapped vuex getters within components become stale. To have a working Counter example, the computed mapped `evenOrOdd` is accessed directly via `$store`. This will be changed back once the stale mapped getter issue (WIP) is fixed.

* feat: added example tests for Counter component

Added tests to cover all the features within the component. Fixes bahmutov/cypress-vue-unit-testbahmutov/cypress-vue-unit-test#6

* minor: following better practices

* fix: refactor Vue initialization in app frame

Refactors how the Vue instance within the component app frame is initialized, and fully fixes Vue integration.
- fixes lingering issues after pull request bahmutov/cypress-vue-unit-testbahmutov/cypress-vue-unit-test#13
- fully fixes bahmutov/cypress-vue-unit-testbahmutov/cypress-vue-unit-test#6
- fixes amirrustam/cypress-vue-unit-testbahmutov/cypress-vue-unit-test#1
- README docs have been updated to reflect refactoring
- 'vue' option has been deprecated (with warning to user) as it's no longer necessary
- spread operator support has been added for upcoming Vuex example

* feat: enhanced Vuex Counter example and test spec

To thoroughly demonstrate Vuex support after the refactoring in commit amirrustam/cypress-vue-unit-test@e8773383, Counter.vue now:
- Utilizes all Vuex mapping functions.
- Can properly use computed mapped getters in its template. This was an issue after bahmutov/cypress-vue-unit-testbahmutov/cypress-vue-unit-test#13.
- Set count state via an input field to demonstrate mapped mutations. Two tests have been added to the spec for this new input field.

Close bahmutov/cypress-vue-unit-testbahmutov/cypress-vue-unit-test#6

* minor: remove redundant declaration
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants