How to mock part of a context in React

Asked

Viewed 13 times

0

Hello I have the following context:

import React from 'react'

const AuthContext = React.createContext({
  isAuth: false,
  login: f => f,
  logoff: f => f
})

const AuthProvider = ({ children }) => {
  const [isAuth, setIsAuth] = React.useState(false)

  const login = () => setIsAuth(true)
  const logoff = () => setIsAuth(false)

  return (
    <AuthContext.Provider value={{ isAuth, login, logoff }}>
      {children}
    </AuthContext.Provider>
  )
}

const useAuthContext = React.useContext(AuthContext)

I need to create a test where the user is already logged in, that is, the isAuth property must be set to true. What I need to do to change this property within a jest test?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.