Skip to content

Commit ddde876

Browse files
test: deprecated syntax
1 parent 5da0ed5 commit ddde876

17 files changed

+51
-100
lines changed

packages/pinia/__tests__/actions.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ describe('Actions', () => {
55
const useStore = () => {
66
// create a new store
77
setActivePinia(createPinia())
8-
return defineStore({
9-
id: 'main',
8+
return defineStore('main', {
109
state: () => ({
1110
a: true,
1211
nested: {
@@ -55,13 +54,11 @@ describe('Actions', () => {
5554
})()
5655
}
5756

58-
const useB = defineStore({
59-
id: 'B',
57+
const useB = defineStore('B', {
6058
state: () => ({ b: 'b' }),
6159
})
6260

63-
const useA = defineStore({
64-
id: 'A',
61+
const useA = defineStore('A', {
6562
state: () => ({ a: 'a' }),
6663
actions: {
6764
swap() {

packages/pinia/__tests__/getters.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ describe('Getters', () => {
99
setActivePinia(createPinia())
1010
})
1111

12-
const useStore = defineStore({
13-
id: 'main',
12+
const useStore = defineStore('main', {
1413
state: () => ({
1514
name: 'Eduardo',
1615
}),
@@ -40,13 +39,11 @@ describe('Getters', () => {
4039
},
4140
})
4241

43-
const useB = defineStore({
44-
id: 'B',
42+
const useB = defineStore('B', {
4543
state: () => ({ b: 'b' }),
4644
})
4745

48-
const useA = defineStore({
49-
id: 'A',
46+
const useA = defineStore('A', {
5047
state: () => ({ a: 'a' }),
5148
getters: {
5249
fromB(): string {

packages/pinia/__tests__/lifespan.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import {
1919

2020
describe('Store Lifespan', () => {
2121
function defineMyStore() {
22-
return defineStore({
23-
id: 'main',
22+
return defineStore('main', {
2423
state: () => ({
2524
a: true,
2625
n: 0,
@@ -118,8 +117,7 @@ describe('Store Lifespan', () => {
118117
const globalWatch = vi.fn()
119118
const destroy = watch(() => pinia.state.value.a?.n, globalWatch)
120119

121-
const useStore = defineStore({
122-
id: 'a',
120+
const useStore = defineStore('a', {
123121
state: () => {
124122
n = n || ref(0)
125123
return { n }

packages/pinia/__tests__/mapHelpers.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import { nextTick, defineComponent, ref, computed } from 'vue'
1414
import { mockWarn } from './vitest-mock-warn'
1515

1616
describe('Map Helpers', () => {
17-
const useStore = defineStore({
18-
id: 'main',
17+
const useStore = defineStore('main', {
1918
state: () => ({
2019
a: true,
2120
n: 0,
@@ -147,8 +146,7 @@ describe('Map Helpers', () => {
147146
})
148147

149148
describe('mapActions', () => {
150-
const useStore = defineStore({
151-
id: 'main',
149+
const useStore = defineStore('main', {
152150
state: () => ({ n: 0 }),
153151
actions: {
154152
increment() {

packages/pinia/__tests__/onAction.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ describe('Subscriptions', () => {
77
const useStore = () => {
88
// create a new store
99
setActivePinia(createPinia())
10-
return defineStore({
11-
id: 'main',
10+
return defineStore('main', {
1211
state: () => ({
1312
user: 'Eduardo',
1413
}),
@@ -168,8 +167,7 @@ describe('Subscriptions', () => {
168167
})
169168

170169
describe('multiple store instances', () => {
171-
const useStore = defineStore({
172-
id: 'main',
170+
const useStore = defineStore('main', {
173171
state: () => ({
174172
name: 'Eduardo',
175173
}),

packages/pinia/__tests__/state.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ describe('State', () => {
151151

152152
const pinia = createPinia()
153153
setActivePinia(pinia)
154-
const useStore = defineStore({
155-
id: 'main',
154+
const useStore = defineStore('main', {
156155
state: () => ({
157156
name,
158157
counter,

packages/pinia/__tests__/store.patch.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ describe('store.$patch', () => {
66
const useStore = () => {
77
// create a new store
88
setActivePinia(createPinia())
9-
return defineStore({
10-
id: 'main',
9+
return defineStore('main', {
1110
state: () => ({
1211
a: true,
1312
nested: {
@@ -22,8 +21,7 @@ describe('store.$patch', () => {
2221
const useArrayStore = () => {
2322
// create a new store
2423
setActivePinia(createPinia())
25-
return defineStore({
26-
id: 'main',
24+
return defineStore('main', {
2725
state: () => ({
2826
items: [{ id: 0 }],
2927
currentItem: { id: 1 },
@@ -141,8 +139,7 @@ describe('store.$patch', () => {
141139
const useStore = (pinia?: Pinia) => {
142140
// create a new store
143141
setActivePinia(pinia || createPinia())
144-
return defineStore({
145-
id: 'main',
142+
return defineStore('main', {
146143
state: () => ({
147144
arr: [] as any[],
148145
name: 'Eduardo',

packages/pinia/__tests__/store.spec.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ describe('Store', () => {
1111
setActivePinia(createPinia())
1212
})
1313

14-
const useStore = defineStore({
15-
id: 'main',
14+
const useStore = defineStore('main', {
1615
state: () => ({
1716
a: true,
1817
nested: {
@@ -23,7 +22,7 @@ describe('Store', () => {
2322
})
2423

2524
it('reuses a store', () => {
26-
const useStore = defineStore({ id: 'main' })
25+
const useStore = defineStore('main', {})
2726
expect(useStore()).toBe(useStore())
2827
})
2928

@@ -56,8 +55,7 @@ describe('Store', () => {
5655
it('works without setting the active pinia', async () => {
5756
setActivePinia(undefined)
5857
const pinia = createPinia()
59-
const useStore = defineStore({
60-
id: 'main',
58+
const useStore = defineStore('main', {
6159
state: () => ({ n: 0 }),
6260
})
6361
const TestComponent = defineComponent({
@@ -100,16 +98,15 @@ describe('Store', () => {
10098
})
10199

102100
it('can create an empty state if no state option is provided', () => {
103-
const store = defineStore({ id: 'some' })()
101+
const store = defineStore('some', {})()
104102

105103
expect(store.$state).toEqual({})
106104
})
107105

108106
it('can hydrate the state', () => {
109107
const pinia = createPinia()
110108
setActivePinia(pinia)
111-
const useStore = defineStore({
112-
id: 'main',
109+
const useStore = defineStore('main', {
113110
state: () => ({
114111
a: true,
115112
nested: {
@@ -177,8 +174,7 @@ describe('Store', () => {
177174

178175
it('should outlive components', async () => {
179176
const pinia = createPinia()
180-
const useStore = defineStore({
181-
id: 'main',
177+
const useStore = defineStore('main', {
182178
state: () => ({ n: 0 }),
183179
})
184180

@@ -250,7 +246,7 @@ describe('Store', () => {
250246

251247
it('reuses stores from parent components', () => {
252248
let s1, s2
253-
const useStore = defineStore({ id: 'one' })
249+
const useStore = defineStore('one', {})
254250
const pinia = createPinia()
255251

256252
const Child = defineComponent({
@@ -277,7 +273,7 @@ describe('Store', () => {
277273
})
278274

279275
it('can share the same pinia in two completely different instances', async () => {
280-
const useStore = defineStore({ id: 'one', state: () => ({ n: 0 }) })
276+
const useStore = defineStore('one', { state: () => ({ n: 0 }) })
281277
const pinia = createPinia()
282278

283279
const Comp = defineComponent({
@@ -314,8 +310,7 @@ describe('Store', () => {
314310

315311
it('can be disposed', () => {
316312
const pinia = createPinia()
317-
const useStore = defineStore({
318-
id: 'main',
313+
const useStore = defineStore('main', {
319314
state: () => ({ n: 0 }),
320315
})
321316

@@ -341,8 +336,7 @@ describe('Store', () => {
341336
it('warns when state is created with a class constructor', () => {
342337
class MyState {}
343338

344-
const useMyStore = defineStore({
345-
id: 'store',
339+
const useMyStore = defineStore('store', {
346340
state: () => new MyState(),
347341
})
348342
useMyStore()
@@ -351,17 +345,15 @@ describe('Store', () => {
351345

352346
it('only warns about constructors when store is initially created', () => {
353347
class MyState {}
354-
const useMyStore = defineStore({
355-
id: 'arrowInit',
348+
const useMyStore = defineStore('arrowInit', {
356349
state: () => new MyState(),
357350
})
358351
useMyStore()
359352
expect(warnTextCheckPlainObject('arrowInit')).toHaveBeenWarnedTimes(1)
360353
})
361354

362355
it('does not warn when state is created with a plain object', () => {
363-
const useMyStore = defineStore({
364-
id: 'poInit',
356+
const useMyStore = defineStore('poInit', {
365357
state: () => ({ someValue: undefined }),
366358
})
367359
useMyStore()

packages/pinia/__tests__/storePlugins.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ describe('store plugins', () => {
194194

195195
it('passes the options of the options store', async () => {
196196
const options = {
197-
id: 'main',
198197
state: () => ({ n: 0 }),
199198
actions: {
200199
increment() {
@@ -208,7 +207,7 @@ describe('store plugins', () => {
208207
},
209208
},
210209
}
211-
const useStore = defineStore(options)
210+
const useStore = defineStore('main', options)
212211
const pinia = createPinia()
213212
mount({ template: 'none' }, { global: { plugins: [pinia] } })
214213

packages/pinia/__tests__/storeSetup.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ describe('store with setup syntax', () => {
102102

103103
const pinia = createPinia()
104104
setActivePinia(pinia)
105-
const useStore = defineStore({
106-
id: 'main',
105+
const useStore = defineStore('main', {
107106
state: () => ({
108107
name,
109108
counter,

0 commit comments

Comments
 (0)