-
Notifications
You must be signed in to change notification settings - Fork 7
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
Multi selection - implements #22 #23
Conversation
This makes the API more uniform. Previously, elements could be either an array or a single element which forces middleware authors to handle both cases. For the users, when calling the test() method, helpers.elements will always contain arrays. However, they can still benefit from the shortcut syntax test({myElement}). In that case, elements will be 'unnaraid', which means that that they can either get an array of elements or a single element depending on their component layout.
I also added two middlewares: The Index middlewareAllows to select a specific element after a multi find
The setValues middleware
|
This middleware allows to select a single element after a multi find
I'll look this over tonight! |
import {Find, SetState, Simulate} from './middleware' | ||
import {Find, SetState, Simulate, SetValues, Index} from './middleware' | ||
|
||
const unarray = (elems) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're making breaking changes, might as well remove this like you said.
So it all looks good to me, just remove the params method, update the readme, add a list of the breaking changes, and I'll merge it unless if @dphaener or @kenwheeler see anything wrong. We need to start a wiki with all of the options and examples |
@@ -1,18 +1,62 @@ | |||
import React from 'react' | |||
let { TestUtils } = React.addons | |||
import React from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add semicolons here?? May be you can add no-semicolon rule to the eslintrc. So, the style is consistent across the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, call me evil, but let's remove them all.
@@ -1,13 +1,13 @@ | |||
import React from 'react' | |||
import {Component} from 'react' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to do import React, { Component } from 'react'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? The React object is not used in those components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are. All the JSX components you write are converted to React.createElement(tagName, ...)
Babel transpiles this but it doesn't import it.
const {elements, name} = findSingleOrMulti(rootElement, selector) | ||
|
||
if (elements.length === 0) | ||
throw new Error(`Could not find element "${selector}"`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing an error there is fine with me
This can be useful to simulate a change event on a bunch of inputs for instance
Rename the 'tests' folder to 'test', which is more standard and moved mocha.opts in there Make the tests fall in two folders: core and middlewares Make eslint a post-test script.
}) | ||
~~~ | ||
|
||
But if you use the `multi` option, you can find nested elements: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should make multi the default, like you said. Also, I don't think I like the root option. The component instance is always available inside the test method if you need it
Ok guys, the final API is like this: Test(<FormComponent login={spy}/>)
.find('input').setValues(['username', 'password']) // multi by default
.and() // come back to the root
.find('form').first().simulate('submit')
.test(() => {
expect(spy.calledWith('username', 'password')).to.be.true;
}) You can now use the What do you think? |
In your example, lets say the sumbit returns error and we want to test with new values for username and password. Then I have to do One way to avoid this is to return is to check if the element is present in elements. But this doesn't allow For finding nested elements, isn't it simpler to write a query like this Are there any generic cases where |
@@ -0,0 +1,3 @@ | |||
export default function And() { | |||
this.root = this.instance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a method inside Test class because it doesn't fit the definition of a middleware.
@vramana I like your suggestions, especially the possibility to name the elements that you find. Right now, the test() method is useful to assert things on the component like its props or state. |
I also fear that leaving the possibility for the user to find something complicated like find('table .nested td') will make them want to do find('table > td.nested') and we will soon be reinventing jquery selectors. |
@geowarin I don't think we need to reinvent them. Even I was thinking this for a while. I think I found a solution. Once we have the DOM for |
That would be awesome, except you cannot call ReactUtils.simulate() on a DOM node, can you? |
Yeah. This is going to be hard I guess. Let me think what can be done. |
Implements #22.
I've added tests for every use case detailed in the issue.
There are a couple of things that can be improved immediately :
I'm looking forward for your reviews and comments :)