biome format --write
This commit is contained in:
parent
8372348148
commit
9262e803ec
415 changed files with 54076 additions and 17419 deletions
|
|
@ -9,7 +9,7 @@ const getMockStorage = () => {
|
|||
let state = {}
|
||||
|
||||
return {
|
||||
getItem: vi.fn(async key => {
|
||||
getItem: vi.fn(async (key) => {
|
||||
console.info('get:', key, state[key])
|
||||
return state[key]
|
||||
}),
|
||||
|
|
@ -19,7 +19,7 @@ const getMockStorage = () => {
|
|||
}),
|
||||
_clear: () => {
|
||||
state = {}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ describe('piniaPersistPlugin', () => {
|
|||
await mockStorage.setItem('pinia-local-test', { a: 3 })
|
||||
|
||||
const useTestStore = defineStore('test', {
|
||||
state: () => ({ a: 1, b: 2 })
|
||||
state: () => ({ a: 1, b: 2 }),
|
||||
})
|
||||
|
||||
const test = useTestStore()
|
||||
|
|
@ -55,7 +55,7 @@ describe('piniaPersistPlugin', () => {
|
|||
|
||||
const useTestStore = defineStore('test', {
|
||||
state: () => ({ a: 1, b: 2, c: { d: 4, e: 5 } }),
|
||||
persist: {}
|
||||
persist: {},
|
||||
})
|
||||
|
||||
const test = useTestStore()
|
||||
|
|
@ -68,7 +68,7 @@ describe('piniaPersistPlugin', () => {
|
|||
|
||||
const useTestStore = defineStore('test', {
|
||||
state: () => ({ a: 1, b: 2, c: { d: 4, e: 5 } }),
|
||||
persist: {}
|
||||
persist: {},
|
||||
})
|
||||
|
||||
const test = useTestStore()
|
||||
|
|
@ -84,7 +84,7 @@ describe('piniaPersistPlugin', () => {
|
|||
|
||||
const useTestStore = defineStore('test', {
|
||||
state: () => ({ a: 1, b: 2, c: { d: 4, e: 5 } }),
|
||||
persist: {}
|
||||
persist: {},
|
||||
})
|
||||
|
||||
const test = useTestStore()
|
||||
|
|
@ -101,18 +101,21 @@ describe('piniaPersistPlugin', () => {
|
|||
const useTestStore = defineStore('test', {
|
||||
state: () => ({ a: 1, b: 2, c: { d: 4, e: 5 } }),
|
||||
persist: {
|
||||
afterLoad (state) {
|
||||
afterLoad(state) {
|
||||
return {
|
||||
...state,
|
||||
a: 5
|
||||
a: 5,
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const test = useTestStore()
|
||||
await test.$persistLoaded
|
||||
expect(await mockStorage.getItem('pinia-local-test')).to.eql({ a: 4, c: { d: 0 } })
|
||||
expect(await mockStorage.getItem('pinia-local-test')).to.eql({
|
||||
a: 4,
|
||||
c: { d: 0 },
|
||||
})
|
||||
expect(test.a).to.eql(5)
|
||||
expect(test.b).to.eql(2)
|
||||
expect(test.c.d).to.eql(0)
|
||||
|
|
@ -124,7 +127,7 @@ describe('piniaPersistPlugin', () => {
|
|||
|
||||
const useTestStore = defineStore('test', {
|
||||
state: () => ({ a: 1, b: 2 }),
|
||||
persist: {}
|
||||
persist: {},
|
||||
})
|
||||
|
||||
const test = useTestStore()
|
||||
|
|
@ -138,29 +141,35 @@ describe('piniaPersistPlugin', () => {
|
|||
test('it saves everything if paths is unspecified', async () => {
|
||||
const useTestStore = defineStore('test', {
|
||||
state: () => ({ a: 1, b: 2 }),
|
||||
persist: {}
|
||||
persist: {},
|
||||
})
|
||||
|
||||
const test = useTestStore()
|
||||
await test.$persistLoaded
|
||||
test.$patch({ a: 3 })
|
||||
await flushPromises()
|
||||
expect(await mockStorage.getItem('pinia-local-test')).to.eql({ a: 3, b: 2 })
|
||||
expect(await mockStorage.getItem('pinia-local-test')).to.eql({
|
||||
a: 3,
|
||||
b: 2,
|
||||
})
|
||||
})
|
||||
|
||||
test('it saves only specified paths', async () => {
|
||||
const useTestStore = defineStore('test', {
|
||||
state: () => ({ a: 1, b: 2, c: { d: 4, e: 5 } }),
|
||||
persist: {
|
||||
paths: ['a', 'c.d']
|
||||
}
|
||||
paths: ['a', 'c.d'],
|
||||
},
|
||||
})
|
||||
|
||||
const test = useTestStore()
|
||||
await test.$persistLoaded
|
||||
test.$patch({ a: 3 })
|
||||
await flushPromises()
|
||||
expect(await mockStorage.getItem('pinia-local-test')).to.eql({ a: 3, c: { d: 4 } })
|
||||
expect(await mockStorage.getItem('pinia-local-test')).to.eql({
|
||||
a: 3,
|
||||
c: { d: 4 },
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -171,8 +180,8 @@ describe('piniaPersistPlugin', () => {
|
|||
state: () => ({ a: 1, b: 2 }),
|
||||
persist: {
|
||||
onSaveSuccess,
|
||||
onSaveError
|
||||
}
|
||||
onSaveError,
|
||||
},
|
||||
})
|
||||
|
||||
const test = useTestStore()
|
||||
|
|
@ -194,26 +203,35 @@ describe('piniaPersistPlugin', () => {
|
|||
const useTestStore = defineStore('test', {
|
||||
state: () => ({ a: 1, b: 2 }),
|
||||
actions: {
|
||||
increaseA () {
|
||||
increaseA() {
|
||||
++this.a
|
||||
},
|
||||
increaseB () {
|
||||
increaseB() {
|
||||
++this.b
|
||||
}
|
||||
},
|
||||
},
|
||||
persist: {
|
||||
saveImmediatelyActions: ['increaseA']
|
||||
}
|
||||
saveImmediatelyActions: ['increaseA'],
|
||||
},
|
||||
})
|
||||
|
||||
const test = useTestStore()
|
||||
await test.$persistLoaded
|
||||
await test.increaseA()
|
||||
expect(await mockStorage.getItem('pinia-local-test')).to.eql({ a: 2, b: 2 })
|
||||
expect(await mockStorage.getItem('pinia-local-test')).to.eql({
|
||||
a: 2,
|
||||
b: 2,
|
||||
})
|
||||
await test.increaseB()
|
||||
expect(await mockStorage.getItem('pinia-local-test')).to.eql({ a: 2, b: 2 })
|
||||
expect(await mockStorage.getItem('pinia-local-test')).to.eql({
|
||||
a: 2,
|
||||
b: 2,
|
||||
})
|
||||
await test.increaseA()
|
||||
expect(await mockStorage.getItem('pinia-local-test')).to.eql({ a: 3, b: 3 })
|
||||
expect(await mockStorage.getItem('pinia-local-test')).to.eql({
|
||||
a: 3,
|
||||
b: 3,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -225,8 +243,8 @@ describe('piniaPersistPlugin', () => {
|
|||
state: () => ({ a: 1, b: 2 }),
|
||||
persist: {
|
||||
onSaveSuccess,
|
||||
onSaveError
|
||||
}
|
||||
onSaveError,
|
||||
},
|
||||
})
|
||||
|
||||
const test = useTestStore()
|
||||
|
|
@ -251,8 +269,8 @@ describe('piniaPersistPlugin', () => {
|
|||
state: () => ({ a: 1, b: 2 }),
|
||||
persist: {
|
||||
onSaveSuccess,
|
||||
onSaveError
|
||||
}
|
||||
onSaveError,
|
||||
},
|
||||
})
|
||||
|
||||
const test = useTestStore()
|
||||
|
|
@ -269,15 +287,15 @@ describe('piniaPersistPlugin', () => {
|
|||
describe('afterLoad', () => {
|
||||
test('it is called with the saved state object', async () => {
|
||||
await mockStorage.setItem('pinia-local-test', { a: 2 })
|
||||
const afterLoad = vi.fn(async orig => {
|
||||
const afterLoad = vi.fn(async (orig) => {
|
||||
return { a: orig.a + 1 }
|
||||
})
|
||||
|
||||
const useTestStore = defineStore('test', {
|
||||
state: () => ({ a: 1, b: 2 }),
|
||||
persist: {
|
||||
afterLoad
|
||||
}
|
||||
afterLoad,
|
||||
},
|
||||
})
|
||||
const test = useTestStore()
|
||||
await test.$persistLoaded
|
||||
|
|
@ -294,8 +312,8 @@ describe('piniaPersistPlugin', () => {
|
|||
const useTestStore = defineStore('test', {
|
||||
state: () => ({ a: 1, b: 2 }),
|
||||
persist: {
|
||||
afterLoad
|
||||
}
|
||||
afterLoad,
|
||||
},
|
||||
})
|
||||
const test = useTestStore()
|
||||
await test.$persistLoaded
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue