Skip to content

Commit

Permalink
Make tests pass with different API names
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored and Brian Vaughn committed Jan 15, 2019
1 parent d6f4790 commit f8aba41
Show file tree
Hide file tree
Showing 17 changed files with 196 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let ReactFeatureFlags = require('shared/ReactFeatureFlags');

let ReactDOM;

const ConcurrentMode = React.unstable_ConcurrentMode;
const ConcurrentMode = React.ConcurrentMode;

const setUntrackedInputValue = Object.getOwnPropertyDescriptor(
HTMLInputElement.prototype,
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('ReactDOMFiberAsync', () => {
});

it('createRoot makes the entire tree async', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
root.render(<div>Hi</div>);
expect(container.textContent).toEqual('');
jest.runAllTimers();
Expand All @@ -185,7 +185,7 @@ describe('ReactDOMFiberAsync', () => {
}
}

const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
root.render(<Component />);
expect(container.textContent).toEqual('');
jest.runAllTimers();
Expand Down
44 changes: 21 additions & 23 deletions packages/react-dom/src/__tests__/ReactDOMRoot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
let React = require('react');
let ReactDOM = require('react-dom');
let ReactDOMServer = require('react-dom/server');
let ConcurrentMode = React.unstable_ConcurrentMode;
let ConcurrentMode = React.ConcurrentMode;

describe('ReactDOMRoot', () => {
let container;
Expand Down Expand Up @@ -63,18 +63,18 @@ describe('ReactDOMRoot', () => {
React = require('react');
ReactDOM = require('react-dom');
ReactDOMServer = require('react-dom/server');
ConcurrentMode = React.unstable_ConcurrentMode;
ConcurrentMode = React.ConcurrentMode;
});

it('renders children', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
root.render(<div>Hi</div>);
jest.runAllTimers();
expect(container.textContent).toEqual('Hi');
});

it('unmounts children', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
root.render(<div>Hi</div>);
jest.runAllTimers();
expect(container.textContent).toEqual('Hi');
Expand All @@ -84,7 +84,7 @@ describe('ReactDOMRoot', () => {
});

it('`root.render` returns a thenable work object', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
const work = root.render(<ConcurrentMode>Hi</ConcurrentMode>);
let ops = [];
work.then(() => {
Expand All @@ -102,7 +102,7 @@ describe('ReactDOMRoot', () => {
});

it('resolves `work.then` callback synchronously if the work already committed', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
const work = root.render(<ConcurrentMode>Hi</ConcurrentMode>);
jest.runAllTimers();
let ops = [];
Expand All @@ -126,7 +126,7 @@ describe('ReactDOMRoot', () => {
// Does not hydrate by default
const container1 = document.createElement('div');
container1.innerHTML = markup;
const root1 = ReactDOM.unstable_createRoot(container1);
const root1 = ReactDOM.createRoot(container1);
root1.render(
<div>
<span />
Expand All @@ -137,7 +137,7 @@ describe('ReactDOMRoot', () => {
// Accepts `hydrate` option
const container2 = document.createElement('div');
container2.innerHTML = markup;
const root2 = ReactDOM.unstable_createRoot(container2, {hydrate: true});
const root2 = ReactDOM.createRoot(container2, {hydrate: true});
root2.render(
<div>
<span />
Expand All @@ -150,7 +150,7 @@ describe('ReactDOMRoot', () => {

it('does not clear existing children', async () => {
container.innerHTML = '<div>a</div><div>b</div>';
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
root.render(
<div>
<span>c</span>
Expand All @@ -170,7 +170,7 @@ describe('ReactDOMRoot', () => {
});

it('can defer a commit by batching it', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
const batch = root.createBatch();
batch.render(<div>Hi</div>);
// Hasn't committed yet
Expand All @@ -193,7 +193,7 @@ describe('ReactDOMRoot', () => {
}
}

const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
const batch = root.createBatch();
batch.render(
<ConcurrentMode>
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('ReactDOMRoot', () => {
ops.push('Foo');
return props.children;
}
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
const batch = root.createBatch();
batch.render(<Foo>Hi</Foo>);
// Flush all async work.
Expand All @@ -244,7 +244,7 @@ describe('ReactDOMRoot', () => {
});

it('can wait for a batch to finish', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
const batch = root.createBatch();
batch.render(<ConcurrentMode>Foo</ConcurrentMode>);

Expand All @@ -266,7 +266,7 @@ describe('ReactDOMRoot', () => {
});

it('`batch.render` returns a thenable work object', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
const batch = root.createBatch();
const work = batch.render('Hi');
let ops = [];
Expand All @@ -285,7 +285,7 @@ describe('ReactDOMRoot', () => {
});

it('can commit an empty batch', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
root.render(<ConcurrentMode>1</ConcurrentMode>);

advanceCurrentTime(2000);
Expand All @@ -302,7 +302,7 @@ describe('ReactDOMRoot', () => {

it('two batches created simultaneously are committed separately', () => {
// (In other words, they have distinct expiration times)
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
const batch1 = root.createBatch();
batch1.render(1);
const batch2 = root.createBatch();
Expand All @@ -318,7 +318,7 @@ describe('ReactDOMRoot', () => {
});

it('commits an earlier batch without committing a later batch', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
const batch1 = root.createBatch();
batch1.render(1);

Expand All @@ -337,7 +337,7 @@ describe('ReactDOMRoot', () => {
});

it('commits a later batch without committing an earlier batch', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
const batch1 = root.createBatch();
batch1.render(1);

Expand All @@ -357,7 +357,7 @@ describe('ReactDOMRoot', () => {
});

it('handles fatal errors triggered by batch.commit()', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
const batch = root.createBatch();
const InvalidType = undefined;
expect(() => batch.render(<InvalidType />)).toWarnDev(
Expand All @@ -369,9 +369,7 @@ describe('ReactDOMRoot', () => {

it('throws a good message on invalid containers', () => {
expect(() => {
ReactDOM.unstable_createRoot(<div>Hi</div>);
}).toThrow(
'unstable_createRoot(...): Target container is not a DOM element.',
);
ReactDOM.createRoot(<div>Hi</div>);
}).toThrow('createRoot(...): Target container is not a DOM element.');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ describe('ReactDOMServerIntegration', () => {
});
});

describe('React.unstable_ConcurrentMode', () => {
describe('React.ConcurrentMode', () => {
itRenders('an concurrent mode with one child', async render => {
let e = await render(
<React.unstable_ConcurrentMode>
<React.ConcurrentMode>
<div>text1</div>
</React.unstable_ConcurrentMode>,
</React.ConcurrentMode>,
);
let parent = e.parentNode;
expect(parent.childNodes[0].tagName).toBe('DIV');
Expand All @@ -121,19 +121,19 @@ describe('ReactDOMServerIntegration', () => {
};
let Footer = props => {
return (
<React.unstable_ConcurrentMode>
<React.ConcurrentMode>
<h2>footer</h2>
<h3>about</h3>
</React.unstable_ConcurrentMode>
</React.ConcurrentMode>
);
};
let e = await render(
<React.unstable_ConcurrentMode>
<React.ConcurrentMode>
<div>text1</div>
<span>text2</span>
<Header />
<Footer />
</React.unstable_ConcurrentMode>,
</React.ConcurrentMode>,
);
let parent = e.parentNode;
expect(parent.childNodes[0].tagName).toBe('DIV');
Expand All @@ -145,21 +145,21 @@ describe('ReactDOMServerIntegration', () => {

itRenders('a nested concurrent mode', async render => {
let e = await render(
<React.unstable_ConcurrentMode>
<React.unstable_ConcurrentMode>
<React.ConcurrentMode>
<React.ConcurrentMode>
<div>text1</div>
</React.unstable_ConcurrentMode>
</React.ConcurrentMode>
<span>text2</span>
<React.unstable_ConcurrentMode>
<React.unstable_ConcurrentMode>
<React.unstable_ConcurrentMode>
<React.ConcurrentMode>
<React.ConcurrentMode>
<React.ConcurrentMode>
{null}
<p />
</React.unstable_ConcurrentMode>
</React.ConcurrentMode>
{false}
</React.unstable_ConcurrentMode>
</React.unstable_ConcurrentMode>
</React.unstable_ConcurrentMode>,
</React.ConcurrentMode>
</React.ConcurrentMode>
</React.ConcurrentMode>,
);
let parent = e.parentNode;
expect(parent.childNodes[0].tagName).toBe('DIV');
Expand All @@ -168,7 +168,7 @@ describe('ReactDOMServerIntegration', () => {
});

itRenders('an empty concurrent mode', async render => {
expect(await render(<React.unstable_ConcurrentMode />)).toBe(null);
expect(await render(<React.ConcurrentMode />)).toBe(null);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ describe('ReactDOMServerIntegration', () => {

itRenders('a Profiler component and its children', async render => {
const element = await render(
<React.unstable_Profiler id="profiler" onRender={jest.fn()}>
<React.Profiler id="profiler" onRender={jest.fn()}>
<div>Test</div>
</React.unstable_Profiler>,
</React.Profiler>,
);
const parent = element.parentNode;
const div = parent.childNodes[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ describe('ReactDOMServerHydration', () => {
it('should be able to render and hydrate Profiler components', () => {
const callback = jest.fn();
const markup = (
<React.unstable_Profiler id="profiler" onRender={callback}>
<React.Profiler id="profiler" onRender={callback}>
<div>Hi</div>
</React.unstable_Profiler>
</React.Profiler>
);

const element = document.createElement('div');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ describe('ChangeEventPlugin', () => {
ReactDOM = require('react-dom');
});
it('text input', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
let input;

let ops = [];
Expand Down Expand Up @@ -533,7 +533,7 @@ describe('ChangeEventPlugin', () => {
});

it('checkbox input', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
let input;

let ops = [];
Expand Down Expand Up @@ -595,7 +595,7 @@ describe('ChangeEventPlugin', () => {
});

it('textarea', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
let textarea;

let ops = [];
Expand Down Expand Up @@ -642,7 +642,7 @@ describe('ChangeEventPlugin', () => {
});

it('parent of input', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
let input;

let ops = [];
Expand Down Expand Up @@ -693,7 +693,7 @@ describe('ChangeEventPlugin', () => {
});

it('is async for non-input events', () => {
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
let input;

let ops = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ describe('SimpleEventPlugin', function() {

it('flushes pending interactive work before extracting event handler', () => {
container = document.createElement('div');
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
document.body.appendChild(container);

let ops = [];
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('SimpleEventPlugin', function() {

it('end result of many interactive updates is deterministic', () => {
container = document.createElement('div');
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
document.body.appendChild(container);

let button;
Expand Down Expand Up @@ -426,9 +426,9 @@ describe('SimpleEventPlugin', function() {
// Intentionally not using the updater form here
() => this.setState({highPriCount: this.state.highPriCount + 1})
}>
<React.unstable_ConcurrentMode>
<React.ConcurrentMode>
<Button highPriCount={this.state.highPriCount} />
</React.unstable_ConcurrentMode>
</React.ConcurrentMode>
</div>
);
}
Expand Down
Loading

0 comments on commit f8aba41

Please sign in to comment.