upperCaseName(): string {
return this.name.toUpperCase()
},
- // works for js users but cannot be typed at the same time as `this`
- // so it will have to be explicitly typed by the user
- // https://github.com/posva/pinia/issues/249
- callCheck(state: any) {
+ callCheck(state) {
setImmediate(() => {
// avoid getting tracked
+ // toRaw(state).callCount++
state.callCount++
})
return state.forCallCheck
},
- doubleName() {
+ doubleName(): string {
return this.upperCaseName
},
- composed() {
+ composed(): string {
return this.upperCaseName + ': ok'
},
// TODO: I can't figure out how to pass `this` as an argument. Not sure
const pinia = createPinia()
localVue.use(PiniaPlugin)
- // FIXME: https://github.com/vuejs/vue-test-utils/issues/1799
-
- it.skip('what', async () => {
- const localVue = createLocalVue()
- const n = 0
- const Component = defineComponent({
- render: (h) => h('p'),
- setup() {
- // console.log('setup', n++)
- },
- })
-
- mount(Component, { localVue })
- })
-
it('state reactivity outlives component life', async () => {
const useStore = defineMyStore()
const inComponentWatch = jest.fn()
// FIXME: remove when the bug is fixed in VTU
+ // https://github.com/vuejs/vue-test-utils/issues/1799
let setupCalled = false
const Component = defineComponent({
store.n++
await nextTick()
- // FIXME: seems to be a bug in composition api
- // expect(inComponentWatch).toHaveBeenCalledTimes(1)
+ expect(inComponentWatch).toHaveBeenCalledTimes(1)
wrapper = mount(Component, { localVue, pinia })
await nextTick()
expect(inComponentWatch).toHaveBeenCalledTimes(2)
})
- // FIXME: same limitation as above
- it.skip('ref in state reactivity outlives component life', async () => {
+ it('ref in state reactivity outlives component life', async () => {
let n: Ref<number>
const globalWatch = jest.fn()
const destroy = watch(() => pinia.state.value.a?.n, globalWatch)
-import { computed, nextTick, ref, watch } from '@vue/composition-api'
+import { computed, nextTick, reactive, ref, watch } from '@vue/composition-api'
import { defineStore, setActivePinia, createPinia, Pinia } from '../src'
describe('State', () => {
expect(spy).toHaveBeenCalledTimes(1)
})
- // FIXME: check why unwrapping is different with composition api
- it.skip('unwraps refs', () => {
+ it('unwraps', () => {
+ const name = ref('Eduardo')
+ const counter = ref(0)
+ const double = computed({
+ get: () => counter.value * 2,
+ set(val) {
+ counter.value = val / 2
+ },
+ })
+
+ const store = reactive({ name, counter, double })
+ expect(store.name).toBe('Eduardo')
+ name.value = 'Ed'
+ expect(store.name).toBe('Ed')
+ store.name = 'Edu'
+ expect(store.name).toBe('Edu')
+
+ double.value = 4
+ expect(store.counter).toBe(2)
+ expect(counter.value).toBe(2)
+ })
+
+ it('unwraps refs', () => {
const name = ref('Eduardo')
const counter = ref(0)
const double = computed({