Skip to content

Added context support - #62

Merged
lelandrichardson merged 1 commit into
masterfrom
lmr--context-support
Dec 10, 2015
Merged

lelandrichardson merged 1 commit into
masterfrom
lmr--context-support

Conversation

@lelandrichardson

Copy link
Copy Markdown
Collaborator

to: @ljharb @goatslacker

Adds support for context with mount and shallow.

The API looks like:

const context = { name: 'foo' };
const wrapper = mount(<Component />, { context });
const context = { name: 'foo' };
const wrapper = shallow(<Component />, { context });

Additionally, there is a .setContext(newContext) prototype method on each wrapper class.

Fixes #49

Note: this will constitute a minor change (new feature, backwards compatible)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this guaranteed, ie, will it throw an exception? I don't see any tests that cover this case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call. will add some tests.

@lelandrichardson

Copy link
Copy Markdown
Collaborator Author

@ljharb tests added. comments addressed.

@ljharb

ljharb commented Dec 9, 2015

Copy link
Copy Markdown
Member

Changes LGTM - @goatslacker should weigh in on the context stuff tho since he's got more experience with it than I

@lelandrichardson

Copy link
Copy Markdown
Collaborator Author

Looking at the coverage info with the line numbers mismatched is a PITA. I'm going to submit a followup PR that fixes istanbul line numbers, as well as improve coverage where needed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're mutating spec here. Is that ok? Seems like a bad idea

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's ok.

@goatslacker

Copy link
Copy Markdown
Contributor

LGTM

lelandrichardson added a commit that referenced this pull request Dec 10, 2015
@lelandrichardson
lelandrichardson merged commit 9d5d3de into master Dec 10, 2015
@lelandrichardson
lelandrichardson deleted the lmr--context-support branch December 10, 2015 01:50
Comment thread src/ReactWrapper.js

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not due to this diff, but the airbnb styleguide shows this closing wrapper to be back 2 spaces. https://github.com/airbnb/javascript/tree/master/react#alignment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tru dat

@kujon

kujon commented May 4, 2016

Copy link
Copy Markdown

Super useful PR. May I ask what is the reason for render not having this functionality?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants