Skip to content

Examples folder #101

Description

@janhesters

So, I've been using RITEway a lot over the last two weeks and I love it, especially for TDD 👌🏻 But there where some edge cases where I wasted up to a couple of hours figuring out the selectors. I think others could save that time.

I'm wondering whether you would be open for an examples/ folder? If you are okay with it, I would include the following cases (for which I already have the code, except for the regex one):

1, Select multiple elements in a React component with the same class (useful for lists, tables).
2, Select input's vaules in a React component
3, Test whether selection is a certain tag (e.g. <button /> or <select /> etc.) in React Component.
4. Add context and dummy required props for propTypes in a React component. This would be in the createComponent factory function. E.g.:

// in the component
Counter.propTypes = {
  onClick: PropTypes.func.isRequired
}

// ... in the test
const createCounter = clickCount =>
  render(
    <ClickCounter clicks={ clickCount } onClick={() => {}} />
  )
;
  1. Regex.
  2. The reducer from your "Unit Testing React Components" article and adding tests for selectors.

I still have 3 questions about these:

  1. Do you even recommend to use propTypes? If not, why not?
  2. You said you would use regex like this: /search text/.test(renderedOutput). I couldn't figure out how you would use this. Could you give a more concrete example?
  3. Is it correct that you would test selectors like this:
const getCount = state => state.counter;

assert({
 given: 'a click count and a click action',
 should: 'add a click to the count',
 actual: getCount({ counter: reducer(3, click()) }),
 expected: 4
});

If you could answer these questions and like the idea of an examples/ folder, I will make a PR asap 😊Also would you like to see another case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions