From 0676ee7b0521eba44abe521bb289c0574e3a8e95 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 17 Jun 2017 00:57:52 -0700 Subject: [PATCH] [Docs] clean up linting errors in ShallowWrapper API docs --- docs/api/ShallowWrapper/at.md | 2 +- docs/api/ShallowWrapper/contains.md | 8 ++--- .../containsAllMatchingElements.md | 4 +-- .../containsAnyMatchingElements.md | 4 +-- .../ShallowWrapper/containsMatchingElement.md | 28 ++++++---------- docs/api/ShallowWrapper/context.md | 2 +- docs/api/ShallowWrapper/debug.md | 31 ++++++++++-------- docs/api/ShallowWrapper/dive.md | 28 +++++++--------- docs/api/ShallowWrapper/every.md | 4 +-- docs/api/ShallowWrapper/everyWhere.md | 4 +-- docs/api/ShallowWrapper/find.md | 2 +- docs/api/ShallowWrapper/first.md | 2 +- docs/api/ShallowWrapper/forEach.md | 6 ++-- docs/api/ShallowWrapper/get.md | 2 +- docs/api/ShallowWrapper/getNode.md | 14 ++++---- docs/api/ShallowWrapper/getNodes.md | 16 ++++------ docs/api/ShallowWrapper/html.md | 28 ++++++---------- docs/api/ShallowWrapper/key.md | 4 +-- docs/api/ShallowWrapper/last.md | 2 +- docs/api/ShallowWrapper/map.md | 6 ++-- docs/api/ShallowWrapper/matchesElement.md | 12 +++---- docs/api/ShallowWrapper/name.md | 10 ++++-- docs/api/ShallowWrapper/prop.md | 24 ++++++++------ docs/api/ShallowWrapper/props.md | 25 ++++++++------- docs/api/ShallowWrapper/reduce.md | 18 +++++------ docs/api/ShallowWrapper/reduceRight.md | 18 +++++------ docs/api/ShallowWrapper/render.md | 20 +++++------- docs/api/ShallowWrapper/setContext.md | 8 ++--- docs/api/ShallowWrapper/setProps.md | 15 +++++---- docs/api/ShallowWrapper/setState.md | 3 +- docs/api/ShallowWrapper/shallow.md | 28 +++++++--------- docs/api/ShallowWrapper/simulate.md | 4 +-- docs/api/ShallowWrapper/slice.md | 28 ++++++++-------- docs/api/ShallowWrapper/some.md | 4 +-- docs/api/ShallowWrapper/someWhere.md | 4 +-- docs/api/ShallowWrapper/tap.md | 7 ++-- docs/api/ShallowWrapper/type.md | 32 +++++++------------ docs/api/ShallowWrapper/unmount.md | 11 +++++-- docs/api/ShallowWrapper/update.md | 7 ++-- 39 files changed, 224 insertions(+), 251 deletions(-) diff --git a/docs/api/ShallowWrapper/at.md b/docs/api/ShallowWrapper/at.md index ef3334cc3..258a7268e 100644 --- a/docs/api/ShallowWrapper/at.md +++ b/docs/api/ShallowWrapper/at.md @@ -19,7 +19,7 @@ Returns a wrapper around the node at a given index of the current wrapper. ```jsx const wrapper = shallow(); -expect(wrapper.find(Foo).at(0).props().foo).to.equal("bar"); +expect(wrapper.find(Foo).at(0).props().foo).to.equal('bar'); ``` diff --git a/docs/api/ShallowWrapper/contains.md b/docs/api/ShallowWrapper/contains.md index 183f13854..fe18295d8 100644 --- a/docs/api/ShallowWrapper/contains.md +++ b/docs/api/ShallowWrapper/contains.md @@ -22,11 +22,11 @@ the ones passed in. ```jsx -const wrapper = shallow( +const wrapper = shallow((
Hello
-); +)); expect(wrapper.contains(
Hello
)).to.equal(true); @@ -37,13 +37,13 @@ expect(wrapper.contains(
)).to.equal(false); ``` ```jsx -const wrapper = shallow( +const wrapper = shallow((
Hello
Goodbye
Again
-); +)); expect(wrapper.contains([ Hello, diff --git a/docs/api/ShallowWrapper/containsAllMatchingElements.md b/docs/api/ShallowWrapper/containsAllMatchingElements.md index 0dca56643..899388209 100644 --- a/docs/api/ShallowWrapper/containsAllMatchingElements.md +++ b/docs/api/ShallowWrapper/containsAllMatchingElements.md @@ -24,13 +24,13 @@ like the nodes passed in. ```jsx -const wrapper = shallow( +const wrapper = shallow((
Hello
Goodbye
Again
-); +)); expect(wrapper.containsAllMatchingElements([ Hello, diff --git a/docs/api/ShallowWrapper/containsAnyMatchingElements.md b/docs/api/ShallowWrapper/containsAnyMatchingElements.md index 95e5ce13a..09a6914f2 100644 --- a/docs/api/ShallowWrapper/containsAnyMatchingElements.md +++ b/docs/api/ShallowWrapper/containsAnyMatchingElements.md @@ -22,13 +22,13 @@ like one of the array passed in. ```jsx -const wrapper = shallow( +const wrapper = shallow((
Hello
Goodbye
Again
-); +)); expect(wrapper.containsAnyMatchingElements([ Bonjour, diff --git a/docs/api/ShallowWrapper/containsMatchingElement.md b/docs/api/ShallowWrapper/containsMatchingElement.md index ab7aae18a..b0e69a79e 100644 --- a/docs/api/ShallowWrapper/containsMatchingElement.md +++ b/docs/api/ShallowWrapper/containsMatchingElement.md @@ -22,28 +22,18 @@ the one passed in. ```jsx -const wrapper = shallow( +const wrapper = shallow((
Hello
-); - -expect(wrapper.containsMatchingElement( -
Hello
-)).to.equal(true); -expect(wrapper.containsMatchingElement( -
Hello
-)).to.equal(true); - -expect(wrapper.containsMatchingElement( -
Hello
-)).to.equal(false); -expect(wrapper.containsMatchingElement( -
Hello
-)).to.equal(false); -expect(wrapper.containsMatchingElement( -
-)).to.equal(false); +)); + +expect(wrapper.containsMatchingElement(
Hello
)).to.equal(true); +expect(wrapper.containsMatchingElement(
Hello
)).to.equal(true); + +expect(wrapper.containsMatchingElement(
Hello
)).to.equal(false); +expect(wrapper.containsMatchingElement(
Hello
)).to.equal(false); +expect(wrapper.containsMatchingElement(
)).to.equal(false); ``` #### Common Gotchas diff --git a/docs/api/ShallowWrapper/context.md b/docs/api/ShallowWrapper/context.md index bda7eeab2..00eb07ac2 100644 --- a/docs/api/ShallowWrapper/context.md +++ b/docs/api/ShallowWrapper/context.md @@ -17,7 +17,7 @@ root component instance. ```jsx const wrapper = shallow( , - { context: { foo: 10 } } + { context: { foo: 10 } }, ); expect(wrapper.context().foo).to.equal(10); expect(wrapper.context('foo')).to.equal(10); diff --git a/docs/api/ShallowWrapper/debug.md b/docs/api/ShallowWrapper/debug.md index 36bd77a24..6d80fea54 100644 --- a/docs/api/ShallowWrapper/debug.md +++ b/docs/api/ShallowWrapper/debug.md @@ -12,18 +12,21 @@ console when tests are not passing when you expect them to. #### Examples ```jsx -class Book extends React.Component { - render() { - const { title, cover } = this.props; - return ( -
-

{title}

- {cover && } -
- ); - } +function Book({ title, cover }) { + return ( +
+

{title}

+ {cover && } +
+ ); } - +Book.propTypes = { + title: PropTypes.string.isRequired, + cover: PropTypes.string, +}; +Book.defaultProps = { + cover: null, +}; ``` ```jsx const wrapper = shallow(); @@ -37,16 +40,16 @@ Outputs to console: ``` ```jsx -const wrapper = shallow( +const wrapper = shallow(( -); +)); console.log(wrapper.debug()); ``` Outputs to console: diff --git a/docs/api/ShallowWrapper/dive.md b/docs/api/ShallowWrapper/dive.md index d56674b13..6b6e71053 100644 --- a/docs/api/ShallowWrapper/dive.md +++ b/docs/api/ShallowWrapper/dive.md @@ -21,26 +21,22 @@ NOTE: can only be called on wrapper of a single non-DOM component element node. #### Examples ```jsx -class Bar extends React.Component { - render() { - return ( -
-
-
- ); - } +function Bar() { + return ( +
+
+
+ ); } ``` ```jsx -class Foo extends React.Component { - render() { - return ( -
- -
- ); - } +function Foo() { + return ( +
+ +
+ ); } ``` diff --git a/docs/api/ShallowWrapper/every.md b/docs/api/ShallowWrapper/every.md index 78fbaa52c..829823948 100644 --- a/docs/api/ShallowWrapper/every.md +++ b/docs/api/ShallowWrapper/every.md @@ -18,13 +18,13 @@ Returns whether or not all of the nodes in the wrapper match the provided select #### Examples ```jsx -const wrapper = shallow( +const wrapper = shallow((
-); +)); expect(wrapper.find('.foo').every('.foo')).to.equal(true); expect(wrapper.find('.foo').every('.qoo')).to.equal(false); expect(wrapper.find('.foo').every('.bar')).to.equal(false); diff --git a/docs/api/ShallowWrapper/everyWhere.md b/docs/api/ShallowWrapper/everyWhere.md index d644625c6..6f86920f4 100644 --- a/docs/api/ShallowWrapper/everyWhere.md +++ b/docs/api/ShallowWrapper/everyWhere.md @@ -18,13 +18,13 @@ Returns whether or not all of the nodes in the wrapper pass the provided predica #### Example ```jsx -const wrapper = shallow( +const wrapper = shallow((
-); +)); expect(wrapper.find('.foo').everyWhere(n => n.hasClass('foo'))).to.equal(true); expect(wrapper.find('.foo').everyWhere(n => n.hasClass('qoo'))).to.equal(false); expect(wrapper.find('.foo').everyWhere(n => n.hasClass('bar'))).to.equal(false); diff --git a/docs/api/ShallowWrapper/find.md b/docs/api/ShallowWrapper/find.md index 85dd30579..6407a3470 100644 --- a/docs/api/ShallowWrapper/find.md +++ b/docs/api/ShallowWrapper/find.md @@ -47,7 +47,7 @@ expect(wrapper.find('Foo')).to.have.length(1); Object Property Selector: ```jsx const wrapper = shallow(); -expect(wrapper.find({prop: 'value'})).to.have.length(1); +expect(wrapper.find({ prop: 'value' })).to.have.length(1); ``` diff --git a/docs/api/ShallowWrapper/first.md b/docs/api/ShallowWrapper/first.md index e7c645abc..30408e946 100644 --- a/docs/api/ShallowWrapper/first.md +++ b/docs/api/ShallowWrapper/first.md @@ -14,5 +14,5 @@ Reduce the set of matched nodes to the first in the set. ```jsx const wrapper = shallow(); -expect(wrapper.find(Foo).first().props().foo).to.equal("bar"); +expect(wrapper.find(Foo).first().props().foo).to.equal('bar'); ``` diff --git a/docs/api/ShallowWrapper/forEach.md b/docs/api/ShallowWrapper/forEach.md index f8e3174e7..baa7e6ef4 100644 --- a/docs/api/ShallowWrapper/forEach.md +++ b/docs/api/ShallowWrapper/forEach.md @@ -21,15 +21,15 @@ instance. #### Example ```jsx -const wrapper = shallow( +const wrapper = shallow((
-); +)); -wrapper.find('.foo').forEach(function (node) { +wrapper.find('.foo').forEach((node) => { expect(node.hasClass('foo')).to.equal(true); }); ``` diff --git a/docs/api/ShallowWrapper/get.md b/docs/api/ShallowWrapper/get.md index 0627333d0..eff3f4340 100644 --- a/docs/api/ShallowWrapper/get.md +++ b/docs/api/ShallowWrapper/get.md @@ -19,7 +19,7 @@ Returns the node at a given index of the current wrapper. ```jsx const wrapper = shallow(); -expect(wrapper.find(Foo).get(0).props.foo).to.equal("bar"); +expect(wrapper.find(Foo).get(0).props.foo).to.equal('bar'); ``` diff --git a/docs/api/ShallowWrapper/getNode.md b/docs/api/ShallowWrapper/getNode.md index 9b5dae298..6480e93e7 100644 --- a/docs/api/ShallowWrapper/getNode.md +++ b/docs/api/ShallowWrapper/getNode.md @@ -15,16 +15,14 @@ If the current wrapper is wrapping the root component, returns the root componen ```jsx const element = ( -
- - -
+
+ + +
); -class MyComponent extends React.Component { - render() { - return element; - } +function MyComponent() { + return element; } const wrapper = shallow(); diff --git a/docs/api/ShallowWrapper/getNodes.md b/docs/api/ShallowWrapper/getNodes.md index ebffd742b..baebe3a15 100644 --- a/docs/api/ShallowWrapper/getNodes.md +++ b/docs/api/ShallowWrapper/getNodes.md @@ -17,15 +17,13 @@ If the current wrapper is wrapping the root component, returns the root componen const one = ; const two = ; -class Test extends React.Component { - render() { - return ( -
- { one } - { two } -
- ); - } +function Test() { + return ( +
+ {one} + {two} +
+ ); } const wrapper = shallow(); diff --git a/docs/api/ShallowWrapper/html.md b/docs/api/ShallowWrapper/html.md index 4a628812d..542f06e32 100644 --- a/docs/api/ShallowWrapper/html.md +++ b/docs/api/ShallowWrapper/html.md @@ -14,33 +14,25 @@ Note: can only be called on a wrapper of a single node. #### Examples ```jsx -class Foo extends React.Component { - render() { - return (
); - } +function Foo() { + return (
); } ``` ```jsx -class Bar extends React.Component { - render() { - return ( -
- -
- ); - } +function Bar() { + return ( +
+ +
+ ); } ``` ```jsx const wrapper = shallow(); -expect(wrapper.html()).to.equal( - `
` -); -expect(wrapper.find(Foo).html()).to.equal( - `
` -); +expect(wrapper.html()).to.equal('
'); +expect(wrapper.find(Foo).html()).to.equal('
'); ``` ```jsx diff --git a/docs/api/ShallowWrapper/key.md b/docs/api/ShallowWrapper/key.md index 72c80d34e..c0487acf9 100644 --- a/docs/api/ShallowWrapper/key.md +++ b/docs/api/ShallowWrapper/key.md @@ -8,11 +8,11 @@ NOTE: can only be called on a wrapper of a single node. ```jsx -const wrapper = shallow( +const wrapper = shallow((
    {['foo', 'bar'].map(s =>
  • {s}
  • )}
-).find('li'); +)).find('li'); expect(wrapper.at(0).key()).to.equal('foo'); expect(wrapper.at(1).key()).to.equal('bar'); ``` diff --git a/docs/api/ShallowWrapper/last.md b/docs/api/ShallowWrapper/last.md index af5883a12..779460b79 100644 --- a/docs/api/ShallowWrapper/last.md +++ b/docs/api/ShallowWrapper/last.md @@ -14,5 +14,5 @@ Reduce the set of matched nodes to the last in the set. ```jsx const wrapper = shallow(); -expect(wrapper.find(Foo).last().props().foo).to.equal("bar"); +expect(wrapper.find(Foo).last().props().foo).to.equal('bar'); ``` diff --git a/docs/api/ShallowWrapper/map.md b/docs/api/ShallowWrapper/map.md index dd2d1e192..a4b019702 100644 --- a/docs/api/ShallowWrapper/map.md +++ b/docs/api/ShallowWrapper/map.md @@ -21,16 +21,16 @@ the original instance. #### Example ```jsx -const wrapper = shallow( +const wrapper = shallow((
bax
bar
baz
-); +)); const texts = wrapper.find('.foo').map(node => node.text()); -expect(texts).to.eql([ 'bax', 'bar', 'baz' ]); +expect(texts).to.eql(['bax', 'bar', 'baz']); ``` diff --git a/docs/api/ShallowWrapper/matchesElement.md b/docs/api/ShallowWrapper/matchesElement.md index 95deea070..63947acaa 100644 --- a/docs/api/ShallowWrapper/matchesElement.md +++ b/docs/api/ShallowWrapper/matchesElement.md @@ -27,22 +27,18 @@ class MyComponent extends React.Component { this.handleClick = this.handleClick.bind(this); } handleClick() { - ... + // ... } render() { return ( -
Hello
+ ); } } const wrapper = shallow(); -expect(wrapper.matchesElement( -
Hello
-)).to.equal(true); -expect(wrapper.matchesElement( -
Hello
-)).to.equal(true); +expect(wrapper.matchesElement(
Hello
)).to.equal(true); +expect(wrapper.matchesElement(
Hello
)).to.equal(true); ``` diff --git a/docs/api/ShallowWrapper/name.md b/docs/api/ShallowWrapper/name.md index 943708660..ae5380e82 100644 --- a/docs/api/ShallowWrapper/name.md +++ b/docs/api/ShallowWrapper/name.md @@ -18,19 +18,23 @@ Note: can only be called on a wrapper of a single node. #### Examples ```jsx -const wrapper = shallow(
); +const wrapper = shallow(
); expect(wrapper.name()).to.equal('div'); ``` ```jsx -const SomeWrappingComponent = () => ; +function SomeWrappingComponent() { + return ; +} const wrapper = shallow(); expect(wrapper.name()).to.equal('Foo'); ``` ```jsx Foo.displayName = 'A cool custom name'; -const SomeWrappingComponent = () => ; +function SomeWrappingComponent() { + return ; +} const wrapper = shallow(); expect(wrapper.name()).to.equal('A cool custom name'); ``` diff --git a/docs/api/ShallowWrapper/prop.md b/docs/api/ShallowWrapper/prop.md index 9c24a62c5..e490294e4 100644 --- a/docs/api/ShallowWrapper/prop.md +++ b/docs/api/ShallowWrapper/prop.md @@ -19,26 +19,30 @@ of the root node of the component. ```jsx -class MyComponent extends React.Component { - render() { - return ( -
Hello
- ) - } +import PropTypes from 'prop-types'; + +function MyComponent({ includedProp }) { + return ( +
Hello
+ ); } +MyComponent.propTypes = { + includedProp: PropTypes.string.isRequired, +}; + const wrapper = shallow(); -expect(wrapper.prop('includedProp')).to.equal("Success!"); +expect(wrapper.prop('includedProp')).to.equal('Success!'); // Warning: .prop(key) only returns values for props that exist in the root node. // See the note above about wrapper.instance().props to return all props in the React component. -wrapper.prop('includedProp'); +console.log(wrapper.prop('includedProp')); // "Success!" -wrapper.prop('excludedProp'); +console.log(wrapper.prop('excludedProp')); // undefined -wrapper.instance().props.excludedProp; +console.log(wrapper.instance().props.excludedProp); // "I'm not included" ``` diff --git a/docs/api/ShallowWrapper/props.md b/docs/api/ShallowWrapper/props.md index bbdd73ea1..477696c4f 100644 --- a/docs/api/ShallowWrapper/props.md +++ b/docs/api/ShallowWrapper/props.md @@ -11,28 +11,31 @@ See [`.instance() => ReactComponent`](instance.md) #### Example - ```jsx -class MyComponent extends React.Component { - render() { - return ( -
Hello
- ) - } +import PropTypes from 'prop-types'; + +function MyComponent(props) { + const { includedProp } = props; + return ( +
Hello
+ ); } +MyComponent.propTypes = { + includedProp: PropTypes.string.isRequired, +}; + const wrapper = shallow(); -expect(wrapper.props().includedProp).to.equal("Success!"); +expect(wrapper.props().includedProp).to.equal('Success!'); // Warning: .props() only returns props that are passed to the root node, // which does not include excludedProp in this example. // See the note above about wrapper.instance().props. -wrapper.props(); +console.log(wrapper.props()); // {children: "Hello", className: "foo bar", includedProp="Success!"} -wrapper.instance().props; +console.log(wrapper.instance().props); // {children: "Hello", className: "foo bar", includedProp:"Success!", excludedProp: "I'm not included"} - ``` diff --git a/docs/api/ShallowWrapper/reduce.md b/docs/api/ShallowWrapper/reduce.md index f587a9dac..2b368a897 100644 --- a/docs/api/ShallowWrapper/reduce.md +++ b/docs/api/ShallowWrapper/reduce.md @@ -26,16 +26,14 @@ first invocation of the reducing function. #### Example ```jsx -class Foo extends React.Component { - render() { - return ( -
- - - -
- ); - } +function Foo() { + return ( +
+ + + +
+ ); } ``` diff --git a/docs/api/ShallowWrapper/reduceRight.md b/docs/api/ShallowWrapper/reduceRight.md index d55e2524e..89cebbaac 100644 --- a/docs/api/ShallowWrapper/reduceRight.md +++ b/docs/api/ShallowWrapper/reduceRight.md @@ -26,16 +26,14 @@ first invocation of the reducing function. #### Example ```jsx -class Foo extends React.Component { - render() { - return ( -
- - - -
- ); - } +function Foo() { + return ( +
+ + + +
+ ); } ``` diff --git a/docs/api/ShallowWrapper/render.md b/docs/api/ShallowWrapper/render.md index d08769623..b9038f626 100644 --- a/docs/api/ShallowWrapper/render.md +++ b/docs/api/ShallowWrapper/render.md @@ -14,22 +14,18 @@ Note: can only be called on a wrapper of a single node. #### Examples ```jsx -class Foo extends React.Component { - render() { - return (
); - } +function Foo() { + return (
); } ``` ```jsx -class Bar extends React.Component { - render() { - return ( -
- -
- ); - } +function Bar() { + return ( +
+ +
+ ); } ``` diff --git a/docs/api/ShallowWrapper/setContext.md b/docs/api/ShallowWrapper/setContext.md index 4ba9fb62f..b02897f3c 100644 --- a/docs/api/ShallowWrapper/setContext.md +++ b/docs/api/ShallowWrapper/setContext.md @@ -21,13 +21,11 @@ NOTE: can only be called on a wrapper instance that is also the root instance. #### Example ```jsx -import React from 'react'; import PropTypes from 'prop-types'; -class SimpleComponent extends React.Component { - render() { - return
{this.context.name}
; - } +function SimpleComponent(props, context) { + const { name } = context; + return
{name}
; } SimpleComponent.contextTypes = { name: PropTypes.string, diff --git a/docs/api/ShallowWrapper/setProps.md b/docs/api/ShallowWrapper/setProps.md index 7f91d89d3..743222437 100644 --- a/docs/api/ShallowWrapper/setProps.md +++ b/docs/api/ShallowWrapper/setProps.md @@ -25,13 +25,16 @@ NOTE: can only be called on a wrapper instance that is also the root instance. #### Example ```jsx -class Foo extends React.Component { - render() { - return ( -
- ); - } +import PropTypes from 'prop-types'; + +function Foo({ name }) { + return ( +
+ ); } +Foo.propTypes = { + name: PropTypes.string.isRequired, +}; ``` ```jsx const wrapper = shallow(); diff --git a/docs/api/ShallowWrapper/setState.md b/docs/api/ShallowWrapper/setState.md index f01a40b4f..f8b92b74c 100644 --- a/docs/api/ShallowWrapper/setState.md +++ b/docs/api/ShallowWrapper/setState.md @@ -30,8 +30,9 @@ class Foo extends React.Component { this.state = { name: 'foo' }; } render() { + const { name } = this.state; return ( -
+
); } } diff --git a/docs/api/ShallowWrapper/shallow.md b/docs/api/ShallowWrapper/shallow.md index bc24de457..f97d5d3ca 100644 --- a/docs/api/ShallowWrapper/shallow.md +++ b/docs/api/ShallowWrapper/shallow.md @@ -21,26 +21,22 @@ NOTE: can only be called on wrapper of a single node. #### Examples ```jsx -class Bar extends React.Component { - render() { - return ( -
-
-
- ); - } +function Bar() { + return ( +
+
+
+ ); } ``` ```jsx -class Foo extends React.Component { - render() { - return ( -
- -
- ); - } +function Foo() { + return ( +
+ +
+ ); } ``` diff --git a/docs/api/ShallowWrapper/simulate.md b/docs/api/ShallowWrapper/simulate.md index 512967b49..efe9003fd 100644 --- a/docs/api/ShallowWrapper/simulate.md +++ b/docs/api/ShallowWrapper/simulate.md @@ -32,7 +32,7 @@ class Foo extends React.Component {
{count} clicks
- this.setState({ count: count + 1 })}> + { this.setState({ count: count + 1 }); }}> Increment
@@ -53,6 +53,6 @@ expect(wrapper.find('.clicks-1').length).to.equal(1); - Currently, event simulation for the shallow renderer does not propagate as one would normally expect in a real environment. As a result, one must call `.simulate()` on the actual node that has the event handler set. -- Even though the name would imply this simulates an actual event, `.simulate()` will in fact +- Even though the name would imply this simulates an actual event, `.simulate()` will in fact target the component's prop based on the event you give it. For example, `.simulate('click')` will actually get the `onClick` prop and call it. diff --git a/docs/api/ShallowWrapper/slice.md b/docs/api/ShallowWrapper/slice.md index e53121966..203253570 100644 --- a/docs/api/ShallowWrapper/slice.md +++ b/docs/api/ShallowWrapper/slice.md @@ -19,26 +19,26 @@ Returns a new wrapper with a subset of the nodes of the original wrapper, accord #### Examples ```jsx -const wrapper = shallow( -
-
-
-
-
-); +const wrapper = shallow(( +
+
+
+
+
+)); expect(wrapper.find('.foo').slice(1)).to.have.length(2); expect(wrapper.find('.foo').slice(1).at(0).hasClass('bar')).to.equal(true); expect(wrapper.find('.foo').slice(1).at(1).hasClass('baz')).to.equal(true); ``` ```jsx -const wrapper = shallow( -
-
-
-
-
-); +const wrapper = shallow(( +
+
+
+
+
+)); expect(wrapper.find('.foo').slice(1, 2)).to.have.length(1); expect(wrapper.find('.foo').slice(1, 2).at(0).hasClass('bar')).to.equal(true); ``` diff --git a/docs/api/ShallowWrapper/some.md b/docs/api/ShallowWrapper/some.md index 7958bd334..593bed552 100644 --- a/docs/api/ShallowWrapper/some.md +++ b/docs/api/ShallowWrapper/some.md @@ -18,13 +18,13 @@ Returns whether or not any of the nodes in the wrapper match the provided select #### Examples ```jsx -const wrapper = shallow( +const wrapper = shallow((
-); +)); expect(wrapper.find('.foo').some('.qoo')).to.equal(true); expect(wrapper.find('.foo').some('.foo')).to.equal(true); expect(wrapper.find('.foo').some('.bar')).to.equal(false); diff --git a/docs/api/ShallowWrapper/someWhere.md b/docs/api/ShallowWrapper/someWhere.md index a850d7cfb..8a174b5b9 100644 --- a/docs/api/ShallowWrapper/someWhere.md +++ b/docs/api/ShallowWrapper/someWhere.md @@ -18,13 +18,13 @@ Returns whether or not any of the nodes in the wrapper pass the provided predica #### Example ```jsx -const wrapper = shallow( +const wrapper = shallow((
-); +)); expect(wrapper.find('.foo').someWhere(n => n.hasClass('qoo'))).to.equal(true); expect(wrapper.find('.foo').someWhere(n => n.hasClass('foo'))).to.equal(true); expect(wrapper.find('.foo').someWhere(n => n.hasClass('bar'))).to.equal(false); diff --git a/docs/api/ShallowWrapper/tap.md b/docs/api/ShallowWrapper/tap.md index e4c518aa1..ea59f8415 100644 --- a/docs/api/ShallowWrapper/tap.md +++ b/docs/api/ShallowWrapper/tap.md @@ -19,15 +19,14 @@ This is helpful when debugging nodes in method chains. ```jsx -const result = shallow( +const result = shallow((
  • xxx
  • yyy
  • zzz
-) +)) .find('li') .tap(n => console.log(n.debug())) -.map(n => n.text()) -; +.map(n => n.text()); ``` diff --git a/docs/api/ShallowWrapper/type.md b/docs/api/ShallowWrapper/type.md index 89cba53e6..45c16bcc0 100644 --- a/docs/api/ShallowWrapper/type.md +++ b/docs/api/ShallowWrapper/type.md @@ -15,44 +15,36 @@ Note: can only be called on a wrapper of a single node. #### Examples ```jsx -class Foo extends React.Component { - render() { - return
; - } +function Foo() { + return
; } const wrapper = shallow(); expect(wrapper.type()).to.equal('div'); ``` ```jsx -class Foo extends React.Component { - render() { - return ( -
- -
- ); - } +function Foo() { + return ( +
+ +
+ ); } const wrapper = shallow(); expect(wrapper.find('.btn').type()).to.equal('button'); ``` ```jsx -class Foo extends React.Component { - render() { - return ; - } +function Foo() { + return ; } const wrapper = shallow(); expect(wrapper.type()).to.equal(Bar); ``` ```jsx -class Null extends React.Component { - render() { - return null; - } +function Null() { + return null; } const wrapper = shallow(); expect(wrapper.type()).to.equal(null); diff --git a/docs/api/ShallowWrapper/unmount.md b/docs/api/ShallowWrapper/unmount.md index 59d252510..5f423deff 100644 --- a/docs/api/ShallowWrapper/unmount.md +++ b/docs/api/ShallowWrapper/unmount.md @@ -12,6 +12,8 @@ an unmount/mount lifecycle. #### Example ```jsx +import PropTypes from 'prop-types'; + const spy = sinon.spy(); class Foo extends React.Component { @@ -19,14 +21,19 @@ class Foo extends React.Component { super(props); this.componentWillUnmount = spy; } + render() { + const { id } = this.props; return ( -
- {this.props.id} +
+ {id}
); } } +Foo.propTypes = { + id: PropTypes.string.isRequired, +}; const wrapper = shallow(); expect(spy.calledOnce).to.equal(false); wrapper.unmount(); diff --git a/docs/api/ShallowWrapper/update.md b/docs/api/ShallowWrapper/update.md index 3dc372353..edbf647d1 100644 --- a/docs/api/ShallowWrapper/update.md +++ b/docs/api/ShallowWrapper/update.md @@ -21,13 +21,14 @@ class ImpureRender extends React.Component { this.count = 0; } render() { - return
{this.count++}
+ this.count += 1; + return
{this.count}
; } } ``` ```jsx const wrapper = shallow(); -expect(wrapper.text()).to.equal("0"); +expect(wrapper.text()).to.equal('0'); wrapper.update(); -expect(wrapper.text()).to.equal("1"); +expect(wrapper.text()).to.equal('1'); ```