Skip to content

WIP: tests for the examples #278

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

Closed
wants to merge 11 commits into from

Conversation

sambs
Copy link
Contributor

@sambs sambs commented Jul 16, 2015

I thought I'd have a go at writing tests for the examples (Issue #157). Am I heading in the right direction?

I separated out the creation of the store, so that I could more easily instantiate it in the actions tests... though maybe I should just be mocking the dispatch and getState and testing at a lower level?

I also added an initialState prop to the App container as its pretty useful to be able to initiate the app in a given state ready for a specific test.


export default class App extends Component {
render() {
const store = createCounterStore(this.props.initialState);
Copy link
Contributor

Choose a reason for hiding this comment

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

The store should not be created inside the render function, otherwise you may have performance and correctness problems. See #287.

@gaearon
Copy link
Contributor

gaearon commented Jul 17, 2015

Thank you so much! It's good, I left a few comments to simplify the approach.

@sambs sambs changed the title WIP: tests for the counter example WIP: tests for the examples Jul 22, 2015
@knowbody
Copy link
Contributor

crap haven't seen that one before, I guess my PR is redundant then

@sambs
Copy link
Contributor Author

sambs commented Jul 29, 2015

@gaearon How do these look? I've learnt more about testing React components as I've progressed, hence the counter components use renderIntoDocument and the todo tests use shallow rendering. The CounterApp tests in particular are more like integration tests at the moment and should maybe be simplified using shallow rendering?

@knowbody
Copy link
Contributor

I had a look at them as I started working on them before as well. They look good to me. Great job @sambs!

@sambs
Copy link
Contributor Author

sambs commented Jul 30, 2015

Thanks @knowbody! Sorry we managed to duplicate our efforts.

@knowbody
Copy link
Contributor

haha, no worries

@gaearon
Copy link
Contributor

gaearon commented Jul 30, 2015

This is RATHER thorough. Extremely fine work.
Do you mind rebasing on the latest breaking-changes-1.0? I'll merge.

@gaearon
Copy link
Contributor

gaearon commented Jul 30, 2015

Whether to use shallow or normal rendering is up to you now. You know about testing React+Redux apps more than me at this point :-)

expect(actions.increment()).toEqual({ type: types.INCREMENT_COUNTER });
});

it('decrement should create descrement action', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

small typo here, should be decrement

@sambs
Copy link
Contributor Author

sambs commented Jul 31, 2015

Looks like I need to refactor this before merging since #373 removed ES7 features.

@gaearon
Copy link
Contributor

gaearon commented Jul 31, 2015

@sambs Yeah. There shouldn't be a lot there right? Occasional spread here and there.

@sambs sambs mentioned this pull request Jul 31, 2015
@sambs
Copy link
Contributor Author

sambs commented Jul 31, 2015

I've rebased against the breaking-changes-1.0 branch, removed ES7 stuff and created a new pull request #380 to keep things nice a clean :)

@sambs sambs closed this Jul 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants