Closed silverbackdan closed 1 year ago
Test fetcher::fetchRoute if meta.cwa is false, to skip
- #103 + in this PR I've also fixed failing tests after code changes
Test watch is called with immediate when it has been defined
- unfortunately, such tests cannot be written for Vue3 components as watch
is called within setup
function. Moreover, since in one component there may be multiple watchers. in order to check whether correct function is called, we had to:
based on all this things, I must admit, that doing all this for testing one flag may be overkill
Test watch is called with immediate when it has been defined
- unfortunately, such tests cannot be written for Vue3 components aswatch
is called withinsetup
function. Moreover, since in one component there may be multiple watchers. in order to check whether correct function is called, we had to:
- move getter function responsible for storing all values we watch into separate computed to check its reference in test
- move watcher function into method to be able to check its reference
based on all this things, I must admit, that doing all this for testing one flag may be overkill
I do have an example to mock the watch function and call the original, wrapping the watch in as a spy but calling the original as well. Then you just check if the function was called with specific arguments. I see what you mean about if there are more watchers and ensuring the flag is called on the correct watcher. However, if the watcher is inside the onMounted
for example, we can mock onMounted
to call it and ensure that watcher was called then... but with some thinking perhaps there is a more succinct way to test.
I have moved process.client
and process.server
into composable, thus I could easily mock it in route-middleware
tests, so last two points are also done
Test watch is called with immediate when it has been defined
- unfortunately, such tests cannot be written for Vue3 components aswatch
is called withinsetup
function. Moreover, since in one component there may be multiple watchers. in order to check whether correct function is called, we had to:
- move getter function responsible for storing all values we watch into separate computed to check its reference in test
- move watcher function into method to be able to check its reference
based on all this things, I must admit, that doing all this for testing one flag may be overkill
I do have an example to mock the watch function and call the original, wrapping the watch in as a spy but calling the original as well. Then you just check if the function was called with specific arguments. I see what you mean about if there are more watchers and ensuring the flag is called on the correct watcher. However, if the watcher is inside the
onMounted
for example, we can mockonMounted
to call it and ensure that watcher was called then... but with some thinking perhaps there is a more succinct way to test.
do you mean you moved watcher function into separate method and called it like this:
doSomething() { }
watch(val, doSomething)
?
Move complex conditionals in ComponentGroup template to computed vars
- ✅
Move signedIn computed var from ComponentGroup to Auth class
- ✅
Test watch is called with immediate when it has been defined
- unfortunately, such tests cannot be written for Vue3 components aswatch
is called withinsetup
function. Moreover, since in one component there may be multiple watchers. in order to check whether correct function is called, we had to:
- move getter function responsible for storing all values we watch into separate computed to check its reference in test
- move watcher function into method to be able to check its reference
based on all this things, I must admit, that doing all this for testing one flag may be overkill
I do have an example to mock the watch function and call the original, wrapping the watch in as a spy but calling the original as well. Then you just check if the function was called with specific arguments. I see what you mean about if there are more watchers and ensuring the flag is called on the correct watcher. However, if the watcher is inside the
onMounted
for example, we can mockonMounted
to call it and ensure that watcher was called then... but with some thinking perhaps there is a more succinct way to test.do you mean you moved watcher function into separate method and called it like this:
doSomething() { } watch(val, doSomething)
?
This was one way I managed to use watchers but also be able to spy on how they were called https://github.com/components-web-app/cwa-nuxt-module/blob/nuxt3/src/runtime/api/fetcher/fetch-status-manager.spec.ts#L35-L49
on ResourceLoader currently we are using onMounted to run code when it is only on client-side - is it worth changing the way we check for this? Code should not be render blocking
- looks like we cannot do much with this since using process.client
check leads to DOM mismatch during hydration
on ResourceLoader currently we are using onMounted to run code when it is only on client-side - is it worth changing the way we check for this? Code should not be render blocking
- looks like we cannot do much with this since usingprocess.client
check leads to DOM mismatch during hydration
Ah yes, forgot about this - indeed in that case it does need to be done once already mounted.
Once signedIn is available from Auth - update the watcher in ComponentGroup
- ✅
Also update ResourceLoader to access the new signedIn computed var from Auth class
- ✅
Test watch is called with immediate when it has been defined
- unfortunately, such tests cannot be written for Vue3 components aswatch
is called withinsetup
function. Moreover, since in one component there may be multiple watchers. in order to check whether correct function is called, we had to:
- move getter function responsible for storing all values we watch into separate computed to check its reference in test
- move watcher function into method to be able to check its reference
based on all this things, I must admit, that doing all this for testing one flag may be overkill
I do have an example to mock the watch function and call the original, wrapping the watch in as a spy but calling the original as well. Then you just check if the function was called with specific arguments. I see what you mean about if there are more watchers and ensuring the flag is called on the correct watcher. However, if the watcher is inside the
onMounted
for example, we can mockonMounted
to call it and ensure that watcher was called then... but with some thinking perhaps there is a more succinct way to test.do you mean you moved watcher function into separate method and called it like this:
doSomething() { } watch(val, doSomething)
?
This was one way I managed to use watchers but also be able to spy on how they were called https://github.com/components-web-app/cwa-nuxt-module/blob/nuxt3/src/runtime/api/fetcher/fetch-status-manager.spec.ts#L35-L49
so you ok with moving function from watcher into separate method for reference check in test?
Hmm I'm not sure we are quite understanding each other.
If we were to be mocking watch
like I am, can't we just check that the function has been called with the correct options in the same test where we are checking the watcher is working?
Great work, thanks
ComponentGroup
template to computed varsComponentGroup
toAuth
classsignedIn
is available fromAuth
- update the watcher inComponentGroup
ResourceLoader
to access the newsignedIn
computed var from Auth classimmediate
when it has been definedonMounted
to run code when it is only on client-side - is it worth changing the way we check for this? Code should not be render blockingprocess.server
andprocess.client
for testing https://github.com/components-web-app/cwa-nuxt-module/pull/102/filesprocess.server
andprocess.client
can be mocked, please do a find in the tests for.todo
and see if we can make these work as well