Skip to content

react-scripts test not working if we use declare context statement inside a class component #13344

@manojadams

Description

@manojadams

Describe the bug

Facing problem while running tests.

Seems like react-scripts do not support following statement inside class components
declare context: React.ContextType<typeof FormContext>;

Did you try recovering your dependencies?

No

(paste the output of the command here.)

Steps to reproduce

(Write your steps here:)

  1. Create an app using command npx create-react-app my-app --template typescript
  2. Create a class component :
import React, { Fragment } from "react";

class TestAbc extends React.Component {
    declare context: React.ContextType<typeof FormContext>;

    render() {
        return <Fragment>Hi</Fragment>
    }
    
}
  1. Create a test case for component created in above step
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';
import TestAbc from './TestAbc';

test('renders learn react link', () => {
  render(<TestAbc />);
});

  1. Run test case using command: npm run test

Expected behaviour

Test case should pass

Actual behaviour

Giving error while running test.
Screenshot 2023-08-24 at 10 58 45 AM

Reproducible demo

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions