Skip to content
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

RFC: Mock subtype #6011

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions examples/react/ProcessedDataComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2004-present Facebook. All Rights Reserved.

import React from 'react';

function processData(data) {
return data.map(x => x * 2);
}

export default class ProcessedData extends React.Component {
constructor(props) {
super(props);
this.state = {processedData: null};
}

static getDerivedStateFromProps(nextProps, prevState) {
return {
processedData: processData(nextProps.data),
};
}

render() {
if (this.state.processedData === null) {
return <p>Loading...</p>;
} else {
return <ul>{this.state.processedData.map(n => <li>n></li>)}</ul>;
}
}
}
28 changes: 28 additions & 0 deletions examples/react/__tests__/automocking_new_lifecycle_methods.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2004-present Facebook. All Rights Reserved.

/* eslint-disable no-unused-vars */

jest.mock('../ProcessedDataComponent');

import React from 'react';
import ReactDOM from 'react-dom';
import * as TestUtils from 'react-dom/test-utils';
import ProcessedDataComponent from '../ProcessedDataComponent';

// ProcessedDataComponent uses 'getDerivedStateFromProps'

class Wrapper extends React.Component {
render() {
// ProcessedDataComponent is mocked out.
return (
<div>
<ProcessedDataComponent data={[1, 2, 3]} />
</div>
);
}
}

it('should render a mocked component containing gDSFP with ReactShallowRenderer', () => {
const render = () => TestUtils.renderIntoDocument(<Wrapper />);
expect(render).not.toThrow();
});
4 changes: 2 additions & 2 deletions examples/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"react": "15.4.2",
"react-dom": "15.4.2"
"react": "16.3.1",
"react-dom": "16.3.1"
},
"devDependencies": {
"babel-jest": "*",
Expand Down
Loading