Replies: 1 comment 2 replies
-
You can run the container in // globalSetup.js
export default function setup({ provide }) {
const data = await initData()
provide('sdk_data', data)
} // setupFile.js
import { inject } from 'vitest'
vi.mock('../sdk', () => {
return inject('sdk_data')
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Some of the data I need for testing, methods are sdk methods provided by our own app container, the project is running in the container's webview, the
For example
// init.ts
I'm writing unit tests now, and some of the methods don't run on the node side or the pure web side. I'm using mock
// init.test.ts
But it's a pain in the ass. I need to run our app container first to get the res of initDeviceReady, then put it in vi.fn, and run vitest after that.
I'm wondering if there's a way to run our app container first, store the initDeviceReady return value, and then when I run vitest, I can just use that value without having to mock it again.
But our app container is running on the phone, not on the node, so I don't know if there's a way to store the value and then use it on the node.
Or can custom-environment https://vitest.dev/guide/environment.html#custom-environment directly emulate your own app container?
Or any other simple programs would be appreciated!
Beta Was this translation helpful? Give feedback.
All reactions