Skip to content

Cypress makes a state to undefined somehow #17574

Closed as not planned
Closed as not planned
@enikonemeth

Description

@enikonemeth

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleno activity on this issue for a long period

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions