set value to context provider in Cypress #21109
Answered
by
muriukialex
muriukialex
asked this question in
Component Testing
Replies: 2 comments 4 replies
-
hello @muratkeremozcan, mind taking a look at this |
Beta Was this translation helpful? Give feedback.
2 replies
-
import { mount } from '@cypress/react'
import SendSurvey from '.../../src/website/Surveys/SendSurvey'
import sendSurveyprops from '../fixtures/surveys/sendSurvey/sendSurveyProps'
import draftId from '../fixtures/surveys/sendSurvey/draftId'
describe('Send Message To all contacts', () => {
beforeEach(() => {
cy.intercept('GET', `**/surveys/1`, {
fixture: 'surveys/survey_draft.json',
})
cy.intercept('GET', `**/surveys/1/survey_questions?**`, {
fixture: 'surveys/survey_questions_draft.json',
})
mount(
<UserContext.Provider value={draftId}>
<SendSurvey props={sendSurveyprops} />
</UserContext.Provider>
)
})
it('should successfully select all contacts from the api', () => {
cy.intercept('POST', '**/drafts', {
fixture: 'sendsurveys/contacts_draft_success.json',
}).as('createContactsDraft')
cy.intercept('GET', '**/contacts?**', {
fixture: 'sendsurveys/all_contacts.json',
}).as('fetchAllContacts')
cy.get('[data-testid=all-contacts]').click()
cy.wait('@fetchAllContacts')
cy.get('[data-testid=submit-recipients]').click()
cy.contains('Successfully added the contacts.')
})
})
|
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
muriukialex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, the challenge I have is explained below
Am trying to set a
draft_id
value after thesubmit-recipients
data-testid is clicked.The beforementioned value is passed to a React ContextProvider that wraps my component named
SendSurvey
which in fact uses thedraft_id
valueMy 2 questions are
How do I import the
SendSurvey
component to the test spec written below?How do I wrap my ContextProvider around the
SendSurvey
component (assuming we imported this component successfully) and pass in thedraft_id
value to its ContextProvider?The actual test spec
Beta Was this translation helpful? Give feedback.
All reactions