-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for optional chaining and null coalescing (#7952)
- Loading branch information
1 parent
d12b4b6
commit 5cdc3cc
Showing
6 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ages/react-scripts/fixtures/kitchensink/template/src/features/syntax/NullishCoalescing.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
function load() { | ||
return [ | ||
{ id: 1, name: '1' }, | ||
{ id: 2, name: '2' }, | ||
{ id: 3, name: '3' }, | ||
{ id: 4, name: '4' }, | ||
]; | ||
} | ||
|
||
export default class extends Component { | ||
static propTypes = { | ||
onReady: PropTypes.func.isRequired, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { users: [] }; | ||
} | ||
|
||
async componentDidMount() { | ||
const users = load(); | ||
this.setState({ users }); | ||
} | ||
|
||
componentDidUpdate() { | ||
this.props.onReady(); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div id="feature-nullish-coalescing"> | ||
{this.state.users.map(user => ( | ||
<div key={user.id}>{user.name ?? 'John Doe'}</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...react-scripts/fixtures/kitchensink/template/src/features/syntax/NullishCoalescing.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import NullishCoalescing from './NullishCoalescing'; | ||
|
||
describe('nullish coalescing', () => { | ||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
return new Promise(resolve => { | ||
ReactDOM.render(<NullishCoalescing onReady={resolve} />, div); | ||
}); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
packages/react-scripts/fixtures/kitchensink/template/src/features/syntax/OptionalChaining.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
function load() { | ||
return [ | ||
{ id: 1, name: '1' }, | ||
{ id: 2, name: '2' }, | ||
{ id: 3, name: '3' }, | ||
{ id: 4, name: '4' }, | ||
]; | ||
} | ||
|
||
export default class extends Component { | ||
static propTypes = { | ||
onReady: PropTypes.func.isRequired, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { users: [] }; | ||
} | ||
|
||
async componentDidMount() { | ||
const users = load?.(); | ||
this.setState({ users }); | ||
} | ||
|
||
componentDidUpdate() { | ||
this.props.onReady(); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div id="feature-optional-chaining"> | ||
{this.state.users.map(user => ( | ||
<div key={user.id}>{user?.name}</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../react-scripts/fixtures/kitchensink/template/src/features/syntax/OptionalChaining.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import OptionalChaining from './OptionalChaining'; | ||
|
||
describe('optional chaining', () => { | ||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
return new Promise(resolve => { | ||
ReactDOM.render(<OptionalChaining onReady={resolve} />, div); | ||
}); | ||
}); | ||
}); |
s/your're/you're/