RFC: urql-storage-capacitor #3006
productdevbook
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Converted to a discussion, since this isn't an RFC. Basically, on the Vitest side, it just looks like it's giving you the instructions you need. You need to define mocks that vaguely resemble the exports of the packages you're trying to mock. However, your mocks don't seem right, so this is more appropriate: vi.mock('@capacitor/network', () => ({
Network: {
async getStatus() {
return {
connected: true,
connectionType: 'unknown',
}
},
addListener(_eventName: 'networkStatusChange', _callback: () => void) {
return {
remove: () => Promise.resolve(),
}
},
} as import('@capacitor/network').NetworkPlugin,
}))
vi.mock('@capacitor/preferences', () => ({
Preferences: {
async configure(_opts: any) {
/* noop */
},
async set(_opts: any) {
/* noop */
},
async get(_opts: any) {
return { value: '' }
},
async keys() {
return { keys: [] }
},
async remove(_opts: any) {
/* noop */
},
async clear() {
/* noop */
},
async migrate() {
return {
migrated: [],
existing: [],
}
},
async removeOld() {
/* noop */
},
} as import('@capacitor/preferences').PreferencesPlugin,
})) Now, these don't have to be complete and I can see that you're mocking what you need (correctly, it seems) on a per-test basis, but you do have to make sure that you at least get the shape somewhat right in case you're writing a new test that doesn't mock these imports yet. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
https://github.com/productdevbookcom/urql-storage-capacitor
We published the library. I sent a pr here but it was not accepted. That's why I published it on our side.
But we have a deficiency on the gear side, I don't know how to solve the test errors there. I'm currently using the capacitor on the plug-in side and it works great.
Can you help me with the fix on the test side?
Also, can we add this library to your documentation?
Thank you.
Mehmet
Beta Was this translation helpful? Give feedback.
All reactions