I have a basic react component using recoil, like:
import { useRecoilValue } from 'recoil'
import { isAuthenticated } from 'authentication'
export function CreateMenu() {
const auth = useRecoilValue(isAuthenticated)
return (
<div>
{auth && (<div>hey you're authenticated'</div>)
</div>
)
isAuthenticated is something like:
import {selector} from 'recoil'
export const isAuthenticated = selector<boolean>({
key: 'authselector',
get: ({get}) => {
return get(authToken)?.isAhtenticated
}
})
Now, I want to mock the above isAuthenticated, so I can test both states of auth, I have tried several methods with jest (to which I'm new, as I'm more used to mocha / sinon approach). But so far I haven't been able to figure out how to do it. Reading through (very skimpy) documentation on recoil mocking.. I could move the useRecoilValue() thing to a separate hook, that I could mock, but that feels wrong to me.
any ideas how to approach this?