From bdb618e09860af8925a87cc29620e710d0806cf7 Mon Sep 17 00:00:00 2001 From: Caden Date: Sat, 19 Sep 2020 23:47:24 -0700 Subject: [PATCH] [Docs] `shallow`/`mount`: fix examples, and make them consistent --- docs/api/ReactWrapper/equals.md | 6 +++++- docs/api/ReactWrapper/every.md | 1 - docs/api/ReactWrapper/everyWhere.md | 2 +- docs/api/ReactWrapper/first.md | 2 +- docs/api/ReactWrapper/instance.md | 8 ++++---- docs/api/ReactWrapper/matchesElement.md | 2 +- docs/api/ReactWrapper/render.md | 3 ++- docs/api/ReactWrapper/simulate.md | 8 ++++---- docs/api/ReactWrapper/type.md | 5 +++-- docs/api/ShallowWrapper/equals.md | 4 ++++ docs/api/ShallowWrapper/every.md | 1 - docs/api/ShallowWrapper/first.md | 2 +- docs/api/ShallowWrapper/render.md | 2 +- 13 files changed, 27 insertions(+), 19 deletions(-) diff --git a/docs/api/ReactWrapper/equals.md b/docs/api/ReactWrapper/equals.md index dab98ce34..664231b2e 100644 --- a/docs/api/ReactWrapper/equals.md +++ b/docs/api/ReactWrapper/equals.md @@ -21,7 +21,11 @@ like the one passed in. ```jsx -const wrapper = mount(); +function MyComponent() { + return
; +} + +const wrapper = mount().childAt(0); expect(wrapper.equals(
)).to.equal(true); ``` diff --git a/docs/api/ReactWrapper/every.md b/docs/api/ReactWrapper/every.md index 7dda0c423..b597f7515 100644 --- a/docs/api/ReactWrapper/every.md +++ b/docs/api/ReactWrapper/every.md @@ -33,5 +33,4 @@ expect(wrapper.find('.foo').every('.bar')).to.equal(false); #### Related Methods - [`.someWhere(predicate) => Boolean`](someWhere.md) -- [`.every(selector) => Boolean`](every.md) - [`.everyWhere(predicate) => Boolean`](everyWhere.md) diff --git a/docs/api/ReactWrapper/everyWhere.md b/docs/api/ReactWrapper/everyWhere.md index f8e972c59..afc6615e8 100644 --- a/docs/api/ReactWrapper/everyWhere.md +++ b/docs/api/ReactWrapper/everyWhere.md @@ -35,4 +35,4 @@ expect(wrapper.find('.foo').everyWhere((n) => n.hasClass('bar'))).to.equal(false - [`.some(selector) => Boolean`](some.md) - [`.every(selector) => Boolean`](every.md) -- [`.everyWhere(predicate) => Boolean`](everyWhere.md) + diff --git a/docs/api/ReactWrapper/first.md b/docs/api/ReactWrapper/first.md index 7da199b55..5825dc914 100644 --- a/docs/api/ReactWrapper/first.md +++ b/docs/api/ReactWrapper/first.md @@ -18,5 +18,5 @@ expect(wrapper.find(Foo).first().props().foo).to.equal('bar'); #### Related Methods -- [`.at(index) => ReactWrapper`](at.md) - retrieve any wrapper node +- [`.at(index) => ReactWrapper`](at.md) - retrieve a wrapper node at given index - [`.last() => ReactWrapper`](last.md) diff --git a/docs/api/ReactWrapper/instance.md b/docs/api/ReactWrapper/instance.md index 6733c7209..d2dc1ae7e 100644 --- a/docs/api/ReactWrapper/instance.md +++ b/docs/api/ReactWrapper/instance.md @@ -27,14 +27,14 @@ class Stateful extends React.Component { #### React 16.x ```jsx -test('shallow wrapper instance should be null', () => { +test('mount wrapper instance should be null', () => { const wrapper = mount(); const instance = wrapper.instance(); expect(instance).to.equal(null); }); -test('shallow wrapper instance should not be null', () => { +test('mount wrapper instance should not be null', () => { const wrapper = mount(); const instance = wrapper.instance(); @@ -44,14 +44,14 @@ test('shallow wrapper instance should not be null', () => { #### React 15.x ```jsx -test('shallow wrapper instance should not be null', () => { +test('mount wrapper instance should not be null', () => { const wrapper = mount(); const instance = wrapper.instance(); expect(instance).to.be.instanceOf(Stateless); }); -test('shallow wrapper instance should not be null', () => { +test('mount wrapper instance should not be null', () => { const wrapper = mount(); const instance = wrapper.instance(); diff --git a/docs/api/ReactWrapper/matchesElement.md b/docs/api/ReactWrapper/matchesElement.md index a2fb5a267..33fc41c6f 100644 --- a/docs/api/ReactWrapper/matchesElement.md +++ b/docs/api/ReactWrapper/matchesElement.md @@ -40,7 +40,7 @@ class MyComponent extends React.Component { } } -const wrapper = mount(); +const wrapper = mount().childAt(0); expect(wrapper.matchesElement()).to.equal(true); expect(wrapper.matchesElement()).to.equal(true); ``` diff --git a/docs/api/ReactWrapper/render.md b/docs/api/ReactWrapper/render.md index 1695863e6..a25d3f502 100644 --- a/docs/api/ReactWrapper/render.md +++ b/docs/api/ReactWrapper/render.md @@ -29,5 +29,6 @@ function Bar() { ```jsx const wrapper = mount(); -expect(wrapper.find(Foo).render().find('.in-foo')).to.have.lengthOf(1); +expect(wrapper.find('.in-foo')).to.have.lengthOf(1); +expect(wrapper.render().find('.in-foo')).to.have.lengthOf(1); ``` diff --git a/docs/api/ReactWrapper/simulate.md b/docs/api/ReactWrapper/simulate.md index ccfe029c7..2f2c734e3 100644 --- a/docs/api/ReactWrapper/simulate.md +++ b/docs/api/ReactWrapper/simulate.md @@ -71,12 +71,12 @@ const wrapper = mount(( /> )); -expect(wrapper.find('input').at(0).prop('value')).toEqual(10); -expect(wrapper.find('input').at(1).prop('value')).toEqual(20); +expect(wrapper.find('input').at(0).props().value).to.equal(10); +expect(wrapper.find('input').at(1).props().value).to.equal(20); wrapper.find('input').at(0).simulate('change', { target: { name: 'width', value: 50 } }); wrapper.find('input').at(1).simulate('change', { target: { name: 'height', value: 70 } }); -expect(testState.width).toEqual(50); -expect(testState.height).toEqual(70); +expect(testState.width).to.equal(50); +expect(testState.height).to.equal(70); ``` #### Common Gotchas diff --git a/docs/api/ReactWrapper/type.md b/docs/api/ReactWrapper/type.md index bf0632ebb..1a177cd26 100644 --- a/docs/api/ReactWrapper/type.md +++ b/docs/api/ReactWrapper/type.md @@ -17,7 +17,7 @@ If it's `null`, it will be `null`. It must be a single-node wrapper. function Foo() { return
; } -const wrapper = mount(); +const wrapper = mount().childAt(0); expect(wrapper.type()).to.equal('div'); ``` @@ -38,7 +38,8 @@ function Foo() { return ; } const wrapper = mount(); -expect(wrapper.type()).to.equal(Bar); +expect(wrapper.type()).to.equal(Foo); +expect(wrapper.childAt(0).type()).to.equal(Bar); ``` ```jsx diff --git a/docs/api/ShallowWrapper/equals.md b/docs/api/ShallowWrapper/equals.md index 0d3f5e7de..dd1e7859d 100644 --- a/docs/api/ShallowWrapper/equals.md +++ b/docs/api/ShallowWrapper/equals.md @@ -21,6 +21,10 @@ like the one passed in. ```jsx +function MyComponent() { + return
; +} + const wrapper = shallow(); expect(wrapper.equals(
)).to.equal(true); ``` diff --git a/docs/api/ShallowWrapper/every.md b/docs/api/ShallowWrapper/every.md index 829823948..2526a77e0 100644 --- a/docs/api/ShallowWrapper/every.md +++ b/docs/api/ShallowWrapper/every.md @@ -33,5 +33,4 @@ expect(wrapper.find('.foo').every('.bar')).to.equal(false); #### Related Methods - [`.someWhere(predicate) => Boolean`](someWhere.md) -- [`.every(selector) => Boolean`](every.md) - [`.everyWhere(predicate) => Boolean`](everyWhere.md) diff --git a/docs/api/ShallowWrapper/first.md b/docs/api/ShallowWrapper/first.md index 9df930354..12c013743 100644 --- a/docs/api/ShallowWrapper/first.md +++ b/docs/api/ShallowWrapper/first.md @@ -18,5 +18,5 @@ expect(wrapper.find(Foo).first().props().foo).to.equal('bar'); #### Related Methods -- [`.at(index) => ShallowWrapper`](at.md) - retrieve any wrapper node +- [`.at(index) => ShallowWrapper`](at.md) - retrieve a wrapper node at given index - [`.last() => ShallowWrapper`](last.md) diff --git a/docs/api/ShallowWrapper/render.md b/docs/api/ShallowWrapper/render.md index 6065d5d4b..fb88da528 100644 --- a/docs/api/ShallowWrapper/render.md +++ b/docs/api/ShallowWrapper/render.md @@ -30,5 +30,5 @@ function Bar() { ```jsx const wrapper = shallow(); expect(wrapper.find('.in-foo')).to.have.lengthOf(0); -expect(wrapper.find(Foo).render().find('.in-foo')).to.have.lengthOf(1); +expect(wrapper.render().find('.in-foo')).to.have.lengthOf(1); ```