Skip to content

Commit

Permalink
react-dom: convert packages/react-dom/src/__tests__ (#11776)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim authored and gaearon committed Dec 5, 2017
1 parent 1637b43 commit 48616e5
Show file tree
Hide file tree
Showing 58 changed files with 1,591 additions and 1,579 deletions.
60 changes: 30 additions & 30 deletions packages/react-dom/src/__tests__/CSSPropertyOperations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,76 +9,76 @@

'use strict';

var React = require('react');
var ReactDOM = require('react-dom');
var ReactDOMServer = require('react-dom/server');
const React = require('react');
const ReactDOM = require('react-dom');
const ReactDOMServer = require('react-dom/server');

function normalizeCodeLocInfo(str) {
return str && str.replace(/at .+?:\d+/g, 'at **');
}

describe('CSSPropertyOperations', () => {
it('should automatically append `px` to relevant styles', () => {
var styles = {
const styles = {
left: 0,
margin: 16,
opacity: 0.5,
padding: '4px',
};
var div = <div style={styles} />;
var html = ReactDOMServer.renderToString(div);
const div = <div style={styles} />;
const html = ReactDOMServer.renderToString(div);
expect(html).toContain('"left:0;margin:16px;opacity:0.5;padding:4px"');
});

it('should trim values', () => {
var styles = {
const styles = {
left: '16 ',
opacity: 0.5,
right: ' 4 ',
};
var div = <div style={styles} />;
var html = ReactDOMServer.renderToString(div);
const div = <div style={styles} />;
const html = ReactDOMServer.renderToString(div);
expect(html).toContain('"left:16;opacity:0.5;right:4"');
});

it('should not append `px` to styles that might need a number', () => {
var styles = {
const styles = {
flex: 0,
opacity: 0.5,
};
var div = <div style={styles} />;
var html = ReactDOMServer.renderToString(div);
const div = <div style={styles} />;
const html = ReactDOMServer.renderToString(div);
expect(html).toContain('"flex:0;opacity:0.5"');
});

it('should create vendor-prefixed markup correctly', () => {
var styles = {
const styles = {
msTransition: 'none',
MozTransition: 'none',
};
var div = <div style={styles} />;
var html = ReactDOMServer.renderToString(div);
const div = <div style={styles} />;
const html = ReactDOMServer.renderToString(div);
expect(html).toContain('"-ms-transition:none;-moz-transition:none"');
});

it('should set style attribute when styles exist', () => {
var styles = {
const styles = {
backgroundColor: '#000',
display: 'none',
};
var div = <div style={styles} />;
var root = document.createElement('div');
let div = <div style={styles} />;
const root = document.createElement('div');
div = ReactDOM.render(div, root);
expect(/style=".*"/.test(root.innerHTML)).toBe(true);
});

it('should not set style attribute when no styles exist', () => {
var styles = {
const styles = {
backgroundColor: null,
display: null,
};
var div = <div style={styles} />;
var html = ReactDOMServer.renderToString(div);
const div = <div style={styles} />;
const html = ReactDOMServer.renderToString(div);
expect(/style=/.test(html)).toBe(false);
});

Expand All @@ -92,7 +92,7 @@ describe('CSSPropertyOperations', () => {
}

spyOnDev(console, 'error');
var root = document.createElement('div');
const root = document.createElement('div');
ReactDOM.render(<Comp />, root);
if (__DEV__) {
expect(console.error.calls.count()).toBe(1);
Expand All @@ -114,11 +114,11 @@ describe('CSSPropertyOperations', () => {
}

spyOnDev(console, 'error');
var styles = {
const styles = {
'-ms-transform': 'translate3d(0, 0, 0)',
'-webkit-transform': 'translate3d(0, 0, 0)',
};
var root = document.createElement('div');
const root = document.createElement('div');
ReactDOM.render(<Comp />, root);
ReactDOM.render(<Comp style={styles} />, root);

Expand Down Expand Up @@ -155,7 +155,7 @@ describe('CSSPropertyOperations', () => {
}

spyOnDev(console, 'error');
var root = document.createElement('div');
const root = document.createElement('div');
ReactDOM.render(<Comp />, root);
if (__DEV__) {
// msTransform is correct already and shouldn't warn
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('CSSPropertyOperations', () => {
}

spyOnDev(console, 'error');
var root = document.createElement('div');
const root = document.createElement('div');
ReactDOM.render(<Comp />, root);
if (__DEV__) {
expect(console.error.calls.count()).toBe(2);
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('CSSPropertyOperations', () => {
}

spyOnDev(console, 'error');
var root = document.createElement('div');
const root = document.createElement('div');
ReactDOM.render(<Comp />, root);

if (__DEV__) {
Expand All @@ -243,7 +243,7 @@ describe('CSSPropertyOperations', () => {
}
}

var root = document.createElement('div');
const root = document.createElement('div');
ReactDOM.render(<Comp />, root);
});

Expand All @@ -257,7 +257,7 @@ describe('CSSPropertyOperations', () => {
}

spyOnDev(console, 'error');
var root = document.createElement('div');
const root = document.createElement('div');
ReactDOM.render(<Comp />, root);

if (__DEV__) {
Expand All @@ -277,7 +277,7 @@ describe('CSSPropertyOperations', () => {
}
}

var root = document.createElement('div');
const root = document.createElement('div');
ReactDOM.render(<Comp />, root);

expect(root.children[0].style.Foo).toEqual('5');
Expand Down
34 changes: 17 additions & 17 deletions packages/react-dom/src/__tests__/DOMPropertyOperations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
'use strict';

describe('DOMPropertyOperations', () => {
var React;
var ReactDOM;
let React;
let ReactDOM;

beforeEach(() => {
jest.resetModules();
Expand All @@ -21,20 +21,20 @@ describe('DOMPropertyOperations', () => {

describe('setValueForProperty', () => {
it('should set values as properties by default', () => {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<div title="Tip!" />, container);
expect(container.firstChild.title).toBe('Tip!');
});

it('should set values as attributes if necessary', () => {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<div role="#" />, container);
expect(container.firstChild.getAttribute('role')).toBe('#');
expect(container.firstChild.role).toBeUndefined();
});

it('should set values as namespace attributes if necessary', () => {
var container = document.createElement('svg');
const container = document.createElement('svg');
ReactDOM.render(<image xlinkHref="about:blank" />, container);
expect(
container.firstChild.getAttributeNS(
Expand All @@ -45,7 +45,7 @@ describe('DOMPropertyOperations', () => {
});

it('should set values as boolean properties', () => {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<div disabled="disabled" />, container);
expect(container.firstChild.getAttribute('disabled')).toBe('');
ReactDOM.render(<div disabled={true} />, container);
Expand All @@ -63,40 +63,40 @@ describe('DOMPropertyOperations', () => {
it('should convert attribute values to string first', () => {
// Browsers default to this behavior, but some test environments do not.
// This ensures that we have consistent behavior.
var obj = {
const obj = {
toString: function() {
return 'css-class';
},
};

var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<div className={obj} />, container);
expect(container.firstChild.getAttribute('class')).toBe('css-class');
});

it('should not remove empty attributes for special properties', () => {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<input value="" />, container);
expect(container.firstChild.getAttribute('value')).toBe('');
expect(container.firstChild.value).toBe('');
});

it('should remove for falsey boolean properties', () => {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<div allowFullScreen={false} />, container);
expect(container.firstChild.hasAttribute('allowFullScreen')).toBe(false);
});

it('should remove when setting custom attr to null', () => {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<div data-foo="bar" />, container);
expect(container.firstChild.hasAttribute('data-foo')).toBe(true);
ReactDOM.render(<div data-foo={null} />, container);
expect(container.firstChild.hasAttribute('data-foo')).toBe(false);
});

it('should set className to empty string instead of null', () => {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<div className="selected" />, container);
expect(container.firstChild.className).toBe('selected');
ReactDOM.render(<div className={null} />, container);
Expand All @@ -107,7 +107,7 @@ describe('DOMPropertyOperations', () => {
});

it('should remove property properly for boolean properties', () => {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<div hidden={true} />, container);
expect(container.firstChild.hasAttribute('hidden')).toBe(true);
ReactDOM.render(<div hidden={false} />, container);
Expand All @@ -117,7 +117,7 @@ describe('DOMPropertyOperations', () => {

describe('value mutation method', function() {
it('should update an empty attribute to zero', function() {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(
<input type="radio" value="" onChange={function() {}} />,
container,
Expand All @@ -131,7 +131,7 @@ describe('DOMPropertyOperations', () => {
});

it('should always assign the value attribute for non-inputs', function() {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<progress />, container);
spyOnDevAndProd(container.firstChild, 'setAttribute');
ReactDOM.render(<progress value={30} />, container);
Expand All @@ -142,15 +142,15 @@ describe('DOMPropertyOperations', () => {

describe('deleteValueForProperty', () => {
it('should remove attributes for normal properties', () => {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<div title="foo" />, container);
expect(container.firstChild.getAttribute('title')).toBe('foo');
ReactDOM.render(<div />, container);
expect(container.firstChild.getAttribute('title')).toBe(null);
});

it('should not remove attributes for special properties', () => {
var container = document.createElement('div');
const container = document.createElement('div');
spyOnDev(console, 'error');
ReactDOM.render(
<input type="text" value="foo" onChange={function() {}} />,
Expand Down
8 changes: 4 additions & 4 deletions packages/react-dom/src/__tests__/EventPluginHub-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
jest.mock('../events/isEventSupported');

describe('EventPluginHub', () => {
var React;
var ReactTestUtils;
let React;
let ReactTestUtils;

beforeEach(() => {
jest.resetModules();
Expand All @@ -23,7 +23,7 @@ describe('EventPluginHub', () => {

it('should prevent non-function listeners, at dispatch', () => {
spyOnDev(console, 'error');
var node = ReactTestUtils.renderIntoDocument(
const node = ReactTestUtils.renderIntoDocument(
<div onClick="not a function" />,
);
expect(function() {
Expand All @@ -40,7 +40,7 @@ describe('EventPluginHub', () => {
});

it('should not prevent null listeners, at dispatch', () => {
var node = ReactTestUtils.renderIntoDocument(<div onClick={null} />);
const node = ReactTestUtils.renderIntoDocument(<div onClick={null} />);
expect(function() {
ReactTestUtils.SimulateNative.click(node);
}).not.toThrow();
Expand Down
Loading

0 comments on commit 48616e5

Please sign in to comment.