Defined in: ui/shared/test_helpers/reactSuite/index.js
Prepare a mocha test suite for testing a React component. Every test in the suite will have access to a mounted instance of the component type you're testing, which means you don't have to worry about creating, rendering, or detaching the component.
You may access the instance using the global "subject".
Also, your tests will have access to a bunch of DOM helpers for writing the test scenarios. See ./DOMHelpers.js for those helpers.
| void | createSubject(Object|Function, Function) |
| Boolean | isRunning() |
| React.Component | getSubject() |
| HTMLElement | getContainer() |
| void | remountSubject(Object) |
| void | removeSubject() |
| void | attachToDOM(Function) |
| Boolean | isAttachedToDOM() |
| void | detachFromDOM() |
| HTMLElement | getDOMContainer() |
suite | MochaSuiteThe test suite you're in. I.e, the function passed to describe(). |
type | ReactThe component type/factory/class something you want to test. |
initialProps | ObjectOptional. If you want the component to start out with certain props when it's auto-rendered by the reactSuite, this is the way to do it. Probably useful for required props. Defaults to: |
options | ObjectreactSuite options. Defaults to: |
options.autoMount | BooleanWhether the subject should be automatically mounted and unmounted
in Pass this false if you want manual control of the subject. Defaults to: |
options.immediatelyAttachToDOM | BooleanWhen true, the subject's container node will be attached to the DOM before the subject gets mounted. This is necessary for components that use libraries/or rely on DOM operations when they mount. Defaults to: |
options.requiresRouterContext | BooleanConvenience option for calling "stubRoutes()" with an empty route-set. Use this if you need the component to be set up in a RR context but no route stubbing is necessary. Defaults to: |
TestHelpers.ReactSuiteAPI |
Example
var reactSuite = require("test_helpers/reactSuite");
describe('MyComponent', function() {
reactSuite(this, require("components/MyComponent"));
it("should mount without errors", function() {
// subject will now point to the mounted instance of MyComponent:
expect(subject.isMounted()).to.equal(true);
});
});HTMLElementThe DOM node the subject will be attached to if running in inspect mode or when TestHelpers.reactSuite#UI.attachToDOM is called. |
Attach the component to the inspection DOM node which resides in the document DOM tree. This could be needed for things that rely on the visibility of the component.
callback | FunctionCallback to invoke when the subject is inserted into the DOM. |
callback.detachFromDOM | FunctionA callback that will detach the component from the DOM. Call this when you no longer need the component to be in the DOM. This is done automatically for you when the suite is torn down. Optionally, you can call TestHelpers.reactSuite#UI.detachFromDOM manually. |
Render and mount an instance of the test subject.
initialProps | Object|FunctionA set of props that the component should be mounted with. If this is a function, it must return an Object. |
done | FunctionA callback that will be invoked when the subject is fully mounted and ready to be operated on. |
Unknown tag:
{
"type": "emit",
"string": "",
"typeInfo": {
"name": null,
"description": null,
"isOptional": null,
"defaultValue": null,
"type": null
},
"line": 45
}HTMLElementThe DOM node the subject was mounted on. |
React.ComponentThe instance of the test subject. This is normally found in the global "subject" variable. |
BooleanWhether the component is currently visible in the document DOM tree. |
BooleanWhether the subject is currently mounted and can be operated on. |
Unmount and mount the subject again with new initial props.
This will trigger the componentWillUnmount() hook!
initialProps | ObjectThe new set of props to remount with. |
Unknown tag:
{
"type": "emit",
"string": "",
"typeInfo": {
"name": null,
"description": null,
"isOptional": null,
"defaultValue": null,
"type": null
},
"line": 108
}Remove the previously created instance in TestHelpers.reactSuite#UI.createSubject. This will also undo all side-effects to the React and Ember routes.
Unknown tag:
{
"type": "emit",
"string": "",
"typeInfo": {
"name": null,
"description": null,
"isOptional": null,
"defaultValue": null,
"type": null
},
"line": 129
}Made with ♥ using megadoc.