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

Root-level file exports #198

Merged
merged 2 commits into from
Feb 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ReactWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./build/ReactWrapper').default;
1 change: 1 addition & 0 deletions ShallowWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./build/ShallowWrapper').default;
1 change: 1 addition & 0 deletions mount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./build/mount').default;
1 change: 1 addition & 0 deletions render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./build/render').default;
1 change: 1 addition & 0 deletions shallow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./build/shallow').default;
52 changes: 11 additions & 41 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,14 @@
import cheerio from 'cheerio';
import ReactWrapper from './ReactWrapper';
import ShallowWrapper from './ShallowWrapper';
import { renderToStaticMarkup } from './react-compat';

/**
* Mounts and renders a react component into the document and provides a testing wrapper around it.
*
* @param node
* @returns {ReactWrapper}
*/
export function mount(node, options) {
return new ReactWrapper(node, null, options);
}

/**
* Shallow renders a react component and provides a testing wrapper around it.
*
* @param node
* @returns {ShallowWrapper}
*/
export function shallow(node, options) {
return new ShallowWrapper(node, null, options);
}

/**
* Renders a react component into static HTML and provides a cheerio wrapper around it. This is
* somewhat asymmetric with `mount` and `shallow`, which don't use any external libraries, but
* Cheerio's API is pretty close to what we actually want and has a significant amount of utility
* that would be recreating the wheel if we didn't use it.
*
* I think there are a lot of good use cases to use `render` instead of `shallow` or `mount`, and
* thus I'd like to keep this API in here even though it's not really "ours".
*
* @param node
* @returns {Cheerio}
*/
export function render(node) {
const html = renderToStaticMarkup(node);
return cheerio.load(html).root();
}

export { ShallowWrapper as ShallowWrapper };
export { ReactWrapper as ReactWrapper };
import mount from './mount';
import shallow from './shallow';
import render from './render';

export {
render,
shallow,
mount,
ShallowWrapper,
ReactWrapper,
};
11 changes: 11 additions & 0 deletions src/mount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ReactWrapper from './ReactWrapper';

/**
* Mounts and renders a react component into the document and provides a testing wrapper around it.
*
* @param node
* @returns {ReactWrapper}
*/
export default function mount(node, options) {
return new ReactWrapper(node, null, options);
}
19 changes: 19 additions & 0 deletions src/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { renderToStaticMarkup } from './react-compat';
import cheerio from 'cheerio';

/**
* Renders a react component into static HTML and provides a cheerio wrapper around it. This is
* somewhat asymmetric with `mount` and `shallow`, which don't use any external libraries, but
* Cheerio's API is pretty close to what we actually want and has a significant amount of utility
* that would be recreating the wheel if we didn't use it.
*
* I think there are a lot of good use cases to use `render` instead of `shallow` or `mount`, and
* thus I'd like to keep this API in here even though it's not really "ours".
*
* @param node
* @returns {Cheerio}
*/
export default function render(node) {
const html = renderToStaticMarkup(node);
return cheerio.load(html).root();
}
11 changes: 11 additions & 0 deletions src/shallow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ShallowWrapper from './ShallowWrapper';

/**
* Shallow renders a react component and provides a testing wrapper around it.
*
* @param node
* @returns {ShallowWrapper}
*/
export default function shallow(node, options) {
return new ShallowWrapper(node, null, options);
}