Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

context options for mount are not being applied #1959

Open
2 of 13 tasks
bucketclan opened this issue Jan 1, 2019 · 1 comment
Open
2 of 13 tasks

context options for mount are not being applied #1959

bucketclan opened this issue Jan 1, 2019 · 1 comment

Comments

@bucketclan
Copy link

bucketclan commented Jan 1, 2019

const context = { name: "foo", id: 1};

  const wrapper = mount(<MyComponent />, {
    context,
    childContextTypes: { name: PropTypes.string, id: PropTypes.number }
  });

  expect(wrapper.context().name).toBe("foo");

The default context values were initialised as follows:

const MyContext = React.createContext({ id: 0, name: "" });

Current behavior

The test is failing, with the following errors:

expect(received).toBe(expected) // Object.is equality

    Expected: "foo"
    Received: ""

      22 |   });
      23 |
    > 24 |   expect(wrapper.context().name).toBe("foo");
         |                                  ^

      at Object.toBe (src/App.test.js:24:34)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total

Expected behavior

I expect the value of name to be "foo".

Your environment

"dependencies": {
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "react-scripts": "2.1.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "enzyme": "^3.8.0",
    "enzyme-adapter-react-16": "^1.7.1"
  }

API

  • shallow
  • mount
  • render

Adapter

  • enzyme-adapter-react-16
  • enzyme-adapter-react-16.3
  • enzyme-adapter-react-16.2
  • enzyme-adapter-react-16.1
  • enzyme-adapter-react-15
  • enzyme-adapter-react-15.4
  • enzyme-adapter-react-14
  • enzyme-adapter-react-13
  • enzyme-adapter-react-helper
  • others ( )
@ljharb
Copy link
Member

ljharb commented Jan 1, 2019

enzyme does not yet support createContext. See #1553.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants