cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.59k stars 3.15k forks source link

Cypress makes a state to undefined somehow #17574

Closed enikonemeth closed 1 year ago

enikonemeth commented 3 years ago

Current behavior

I got type error reading a React local state during test run because state is undefined. If I repeat the steps manually the state keeps the proper value. This test and source code was working fine with the previous cypress version (7.5.0)

Desired behavior

It should keep the state value of the component.

Test code to reproduce

code snippet:

  const [currentContent, setCurrentContent] = useState<GenericContent>()  --> the state

    useEffect(() => {
    async function getCurrentContent() {
      const result = await repo.load({
        idOrPath: props.contentPath,
      })
      setCurrentContent(result.d) --> here we set the value (it is OK)
    }
    getCurrentContent()
  }, [props.contentPath, repo])

  const selectMemberFunction = (newEntry: EntryType) => {
    if (permissions) {
      permissions.entries.push(newEntry)
    }
    setSelectedListItem(`${newEntry.identity.id}${newEntry.propagates}`)
    openDialog({
      name: 'permission-editor',
      props: {
        entry: newEntry,
        path: currentContent!.Path,  --> during test run this state is undefined (manually it is okay)
        submitCallback: () => {
          setRefreshFlag(!refreshFlag)
        },
        cancelCallback: () => {
          permissions?.entries.pop()
        },
      },
      dialogProps: { maxWidth: 'sm', classes: { container: globalClasses.centeredRight } },
    })
  }

SOURCE: https://github.com/SenseNet/sn-client/blob/develop/apps/sensenet/src/components/view-controls/permission-view.tsx

TEST: https://github.com/SenseNet/sn-client/blob/develop/apps/sensenet/cypress/integration/permission-editor/add_new_permission.spec.ts

Cypress Version

8.1.0

Other

No response

cypress-app-bot commented 1 year ago

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

cypress-app-bot commented 1 year ago

This issue has been closed due to inactivity.