Hi first time trying to make test in cypress and I have a component called comments you are only allow to make comments if you are logged in as a user. So I what to test that, can I mock a user and set my useState/myCurrentUser? actually its though useContext my user is set.
import {Comments} from "../../src/app/risk-modules/risk-pattern-details/components/Comments";
describe('LoginTest.cy.tsx', () => {
// set userauth
it('playground', () => {
cy.mount(<Comments className={'test'} />)
cy.get('#mybutton').click();
})
})
how my comments component looks like, where is has a state called hasAccess, the “hasAccess is the one I want to mock, just set that state to true.
<div className={`card-toolbar ${!hasAccess && classes.isDisabled}`}>
<button
id='mybutton'
data-bs-toggle='modal'
data-bs-target='#kt_modal_comment'
disabled={!hasAccess}
onClick={() => setOpenDialog(!openDialog)}
>
New comment
</button>
</div>
So at the end I want to mock a useContext state called “hasAccess” to true