diff --git a/__tests__/react-dom/ReactFunctionComponent-test.js b/__tests__/react-dom/ReactFunctionComponent-test.js
new file mode 100644
index 0000000..055f36c
--- /dev/null
+++ b/__tests__/react-dom/ReactFunctionComponent-test.js
@@ -0,0 +1,325 @@
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ *
+ * @emails react-core
+ */
+
+'use strict';
+
+let React;
+let ReactDOM;
+let ReactTestUtils;
+
+function FunctionComponent(props) {
+ return
+ );
+ }).not.toThrowError();
+ });
+
+ // it('should throw on string refs in pure functions', () => {
+ // function Child() {
+ // return ;
+ // }
+
+ // expect(function() {
+ // ReactTestUtils.renderIntoDocument();
+ // }).toThrowError(
+ // __LOG__
+ // ? 'Function components cannot have string refs. We recommend using useRef() instead.'
+ // : // It happens because we don't save _owner in production for
+ // // function components.
+ // 'Element ref was specified as a string (me) but no owner was set. This could happen for one of' +
+ // ' the following reasons:\n' +
+ // '1. You may be adding a ref to a function component\n' +
+ // "2. You may be adding a ref to a component that was not created inside a component's render method\n" +
+ // '3. You have multiple copies of React loaded\n' +
+ // 'See https://reactjs.org/link/refs-must-have-owner for more information.',
+ // );
+ // });
+
+ // it('should warn when given a string ref', () => {
+ // function Indirection(props) {
+ // return
{props.children}
;
+ // }
+
+ // class ParentUsingStringRef extends React.Component {
+ // render() {
+ // return (
+ //
+ //
+ //
+ // );
+ // }
+ // }
+
+ // expect(() =>
+ // ReactTestUtils.renderIntoDocument(),
+ // ).toErrorDev(
+ // 'Warning: Function components cannot be given refs. ' +
+ // 'Attempts to access this ref will fail. ' +
+ // 'Did you mean to use React.forwardRef()?\n\n' +
+ // 'Check the render method ' +
+ // 'of `ParentUsingStringRef`.\n' +
+ // ' in FunctionComponent (at **)\n' +
+ // ' in div (at **)\n' +
+ // ' in Indirection (at **)\n' +
+ // ' in ParentUsingStringRef (at **)',
+ // );
+
+ // // No additional warnings should be logged
+ // ReactTestUtils.renderIntoDocument();
+ // });
+
+ // it('should warn when given a function ref', () => {
+ // function Indirection(props) {
+ // return
{props.children}
;
+ // }
+
+ // class ParentUsingFunctionRef extends React.Component {
+ // render() {
+ // return (
+ //
+ // {
+ // expect(arg).toBe(null);
+ // }}
+ // />
+ //
+ // );
+ // }
+ // }
+
+ // expect(() =>
+ // ReactTestUtils.renderIntoDocument(),
+ // ).toErrorDev(
+ // 'Warning: Function components cannot be given refs. ' +
+ // 'Attempts to access this ref will fail. ' +
+ // 'Did you mean to use React.forwardRef()?\n\n' +
+ // 'Check the render method ' +
+ // 'of `ParentUsingFunctionRef`.\n' +
+ // ' in FunctionComponent (at **)\n' +
+ // ' in div (at **)\n' +
+ // ' in Indirection (at **)\n' +
+ // ' in ParentUsingFunctionRef (at **)',
+ // );
+
+ // // No additional warnings should be logged
+ // ReactTestUtils.renderIntoDocument();
+ // });
+
+ // it('deduplicates ref warnings based on element or owner', () => {
+ // // When owner uses JSX, we can use exact line location to dedupe warnings
+ // class AnonymousParentUsingJSX extends React.Component {
+ // render() {
+ // return {}} />;
+ // }
+ // }
+ // Object.defineProperty(AnonymousParentUsingJSX, 'name', {value: undefined});
+
+ // let instance1;
+
+ // expect(() => {
+ // instance1 = ReactTestUtils.renderIntoDocument(
+ // ,
+ // );
+ // }).toErrorDev('Warning: Function components cannot be given refs.');
+ // // Should be deduped (offending element is on the same line):
+ // instance1.forceUpdate();
+ // // Should also be deduped (offending element is on the same line):
+ // ReactTestUtils.renderIntoDocument();
+
+ // // When owner doesn't use JSX, and is anonymous, we warn once per internal instance.
+ // class AnonymousParentNotUsingJSX extends React.Component {
+ // render() {
+ // return React.createElement(FunctionComponent, {
+ // name: 'A',
+ // ref: () => {},
+ // });
+ // }
+ // }
+ // Object.defineProperty(AnonymousParentNotUsingJSX, 'name', {
+ // value: undefined,
+ // });
+
+ // let instance2;
+ // expect(() => {
+ // instance2 = ReactTestUtils.renderIntoDocument(
+ // ,
+ // );
+ // }).toErrorDev('Warning: Function components cannot be given refs.');
+ // // Should be deduped (same internal instance, no additional warnings)
+ // instance2.forceUpdate();
+ // // Could not be differentiated (since owner is anonymous and no source location)
+ // ReactTestUtils.renderIntoDocument();
+
+ // // When owner doesn't use JSX, but is named, we warn once per owner name
+ // class NamedParentNotUsingJSX extends React.Component {
+ // render() {
+ // return React.createElement(FunctionComponent, {
+ // name: 'A',
+ // ref: () => {},
+ // });
+ // }
+ // }
+ // let instance3;
+ // expect(() => {
+ // instance3 = ReactTestUtils.renderIntoDocument();
+ // }).toErrorDev('Warning: Function components cannot be given refs.');
+ // // Should be deduped (same owner name, no additional warnings):
+ // instance3.forceUpdate();
+ // // Should also be deduped (same owner name, no additional warnings):
+ // ReactTestUtils.renderIntoDocument();
+ // });
+
+ // // This guards against a regression caused by clearing the current debug fiber.
+ // // https://github.com/facebook/react/issues/10831
+ // it('should warn when giving a function ref with context', () => {
+ // function Child() {
+ // return null;
+ // }
+ // Child.contextTypes = {
+ // foo: PropTypes.string,
+ // };
+
+ // class Parent extends React.Component {
+ // static childContextTypes = {
+ // foo: PropTypes.string,
+ // };
+ // getChildContext() {
+ // return {
+ // foo: 'bar',
+ // };
+ // }
+ // render() {
+ // return ;
+ // }
+ // }
+
+ // expect(() => ReactTestUtils.renderIntoDocument()).toErrorDev(
+ // 'Warning: Function components cannot be given refs. ' +
+ // 'Attempts to access this ref will fail. ' +
+ // 'Did you mean to use React.forwardRef()?\n\n' +
+ // 'Check the render method ' +
+ // 'of `Parent`.\n' +
+ // ' in Child (at **)\n' +
+ // ' in Parent (at **)',
+ // );
+ // });
+
+ // it('should provide a null ref', () => {
+ // function Child() {
+ // return ;
+ // }
+
+ // const comp = ReactTestUtils.renderIntoDocument();
+ // expect(comp).toBe(null);
+ // });
+
+ // it('should use correct name in key warning', () => {
+ // function Child() {
+ // return
{[]}
;
+ // }
+
+ // expect(() => ReactTestUtils.renderIntoDocument()).toErrorDev(
+ // 'Each child in a list should have a unique "key" prop.\n\n' +
+ // 'Check the render method of `Child`.',
+ // );
+ // });
+
+ // // TODO: change this test after we deprecate default props support
+ // // for function components
+
+ // it('should receive context', () => {
+ // class Parent extends React.Component {
+ // static childContextTypes = {
+ // lang: PropTypes.string,
+ // };
+
+ // getChildContext() {
+ // return {lang: 'en'};
+ // }
+
+ // render() {
+ // return ;
+ // }
+ // }
+
+ // function Child(props, context) {
+ // return
{context.lang}
;
+ // }
+ // Child.contextTypes = {lang: PropTypes.string};
+
+ // const el = document.createElement('div');
+ // ReactDOM.render(, el);
+ // expect(el.textContent).toBe('en');
+ // });
+
+ it('should work with arrow functions', () => {
+ let Child = function () {
+ return ;
+ };
+ // Will create a new bound function without a prototype, much like a native
+ // arrow function.
+ Child = Child.bind(this);
+
+ expect(() => ReactTestUtils.renderIntoDocument()).not.toThrow();
+ });
+
+ it('should allow simple functions to return null', () => {
+ const Child = function () {
+ return null;
+ };
+ expect(() => ReactTestUtils.renderIntoDocument()).not.toThrow();
+ });
+
+ it('should allow simple functions to return false', () => {
+ function Child() {
+ return false;
+ }
+
+ expect(() => ReactTestUtils.renderIntoDocument()).not.toThrow();
+ });
+});
diff --git a/__tests__/react/ReactElement-test.js b/__tests__/react/ReactElement-test.js
index b0ba1b3..967c837 100644
--- a/__tests__/react/ReactElement-test.js
+++ b/__tests__/react/ReactElement-test.js
@@ -14,269 +14,271 @@ let ReactDOM
let ReactTestUtils
describe('ReactElement', () => {
- let ComponentFC
- let originalSymbol
-
- beforeEach(() => {
- jest.resetModules()
-
- // Delete the native Symbol if we have one to ensure we test the
- // unpolyfilled environment.
- originalSymbol = global.Symbol
- global.Symbol = undefined
-
- React = require('../../dist/react')
- ReactDOM = require('../../dist/react-dom')
- ReactTestUtils = require('../utils/test-utils')
-
- // NOTE: We're explicitly not using JSX here. This is intended to test
- // classic JS without JSX.
- ComponentFC = () => {
- return React.createElement('div')
- }
- })
-
- afterEach(() => {
- global.Symbol = originalSymbol
- })
-
- it('uses the fallback value when in an environment without Symbol', () => {
- expect(().$$typeof).toBe('react.element')
- })
-
- it('returns a complete element according to spec', () => {
- const element = React.createElement(ComponentFC)
- expect(element.type).toBe(ComponentFC)
- expect(element.key).toBe(null)
- expect(element.ref).toBe(null)
-
- expect(element.props).toEqual({})
- })
-
- it('allows a string to be passed as the type', () => {
- const element = React.createElement('div')
- expect(element.type).toBe('div')
- expect(element.key).toBe(null)
- expect(element.ref).toBe(null)
- expect(element.props).toEqual({})
- })
-
- it('returns an immutable element', () => {
- const element = React.createElement(ComponentFC)
- expect(() => (element.type = 'div')).not.toThrow()
- })
-
- it('does not reuse the original config object', () => {
- const config = {foo: 1}
- const element = React.createElement(ComponentFC, config)
- expect(element.props.foo).toBe(1)
- config.foo = 2
- expect(element.props.foo).toBe(1)
- })
-
- it('does not fail if config has no prototype', () => {
- const config = Object.create(null, {foo: {value: 1, enumerable: true}})
- const element = React.createElement(ComponentFC, config)
- expect(element.props.foo).toBe(1)
- })
-
- it('extracts key and ref from the config', () => {
- const element = React.createElement(ComponentFC, {
- key: '12',
- ref: '34',
- foo: '56',
+ let ComponentFC
+ let originalSymbol
+
+ beforeEach(() => {
+ jest.resetModules()
+
+ // Delete the native Symbol if we have one to ensure we test the
+ // unpolyfilled environment.
+ originalSymbol = global.Symbol
+ global.Symbol = undefined
+
+ React = require('../../dist/react')
+ ReactDOM = require('../../dist/react-dom')
+ ReactTestUtils = require('../utils/test-utils')
+
+ // NOTE: We're explicitly not using JSX here. This is intended to test
+ // classic JS without JSX.
+ ComponentFC = () => {
+ return React.createElement('div')
+ }
})
- expect(element.type).toBe(ComponentFC)
- expect(element.key).toBe('12')
- expect(element.ref).toBe('34')
- expect(element.props).toEqual({foo: '56'})
- })
-
- it('extracts null key and ref', () => {
- const element = React.createElement(ComponentFC, {
- key: null,
- ref: null,
- foo: '12',
+
+ afterEach(() => {
+ global.Symbol = originalSymbol
+ })
+
+ it('uses the fallback value when in an environment without Symbol', () => {
+ expect(().$$typeof).toBe('react.element')
+ })
+
+ it('returns a complete element according to spec', () => {
+ const element = React.createElement(ComponentFC)
+ expect(element.type).toBe(ComponentFC)
+ expect(element.key).toBe(null)
+ expect(element.ref).toBe(null)
+
+ expect(element.props).toEqual({})
+ })
+
+ it('allows a string to be passed as the type', () => {
+ const element = React.createElement('div')
+ expect(element.type).toBe('div')
+ expect(element.key).toBe(null)
+ expect(element.ref).toBe(null)
+ expect(element.props).toEqual({})
+ })
+
+ it('returns an immutable element', () => {
+ const element = React.createElement(ComponentFC)
+ expect(() => (element.type = 'div')).not.toThrow()
})
- expect(element.type).toBe(ComponentFC)
- expect(element.key).toBe('null')
- expect(element.ref).toBe(null)
- expect(element.props).toEqual({foo: '12'})
- })
-
- it('ignores undefined key and ref', () => {
- const props = {
- foo: '56',
- key: undefined,
- ref: undefined,
- }
- const element = React.createElement(ComponentFC, props)
- expect(element.type).toBe(ComponentFC)
- expect(element.key).toBe(null)
- expect(element.ref).toBe(null)
- expect(element.props).toEqual({foo: '56'})
- })
-
- it('ignores key and ref warning getters', () => {
- const elementA = React.createElement('div')
- const elementB = React.createElement('div', elementA.props)
- expect(elementB.key).toBe(null)
- expect(elementB.ref).toBe(null)
- })
-
- it('coerces the key to a string', () => {
- const element = React.createElement(ComponentFC, {
- key: 12,
- foo: '56',
+
+ it('does not reuse the original config object', () => {
+ const config = {foo: 1}
+ const element = React.createElement(ComponentFC, config)
+ expect(element.props.foo).toBe(1)
+ config.foo = 2
+ expect(element.props.foo).toBe(1)
})
- expect(element.type).toBe(ComponentFC)
- expect(element.key).toBe('12')
- expect(element.ref).toBe(null)
- expect(element.props).toEqual({foo: '56'})
- })
-
- // it('preserves the owner on the element', () => {
- // let element;
-
- // function Wrapper() {
- // element = React.createElement(ComponentFC);
- // return element;
- // }
-
- // const instance = ReactTestUtils.renderIntoDocument(
- // React.createElement(Wrapper)
- // );
- // expect(element._owner.stateNode).toBe(instance);
- // });
-
- // it('merges an additional argument onto the children prop', () => {
- // const a = 1;
- // const element = React.createElement(
- // ComponentFC,
- // {
- // children: 'text'
- // },
- // a
- // );
- // expect(element.props.children).toBe(a);
- // });
-
- it('does not override children if no rest args are provided', () => {
- const element = React.createElement(ComponentFC, {
- children: 'text',
+
+ it('does not fail if config has no prototype', () => {
+ const config = Object.create(null, {foo: {value: 1, enumerable: true}})
+ const element = React.createElement(ComponentFC, config)
+ expect(element.props.foo).toBe(1)
+ })
+
+ it('extracts key and ref from the config', () => {
+ const element = React.createElement(ComponentFC, {
+ key: '12',
+ ref: '34',
+ foo: '56',
+ })
+ expect(element.type).toBe(ComponentFC)
+ expect(element.key).toBe('12')
+ expect(element.ref).toBe('34')
+ expect(element.props).toEqual({foo: '56'})
+ })
+
+ it('extracts null key and ref', () => {
+ const element = React.createElement(ComponentFC, {
+ key: null,
+ ref: null,
+ foo: '12',
+ })
+ expect(element.type).toBe(ComponentFC)
+ expect(element.key).toBe('null')
+ expect(element.ref).toBe(null)
+ expect(element.props).toEqual({foo: '12'})
+ })
+
+ it('ignores undefined key and ref', () => {
+ const props = {
+ foo: '56',
+ key: undefined,
+ ref: undefined,
+ }
+ const element = React.createElement(ComponentFC, props)
+ expect(element.type).toBe(ComponentFC)
+ expect(element.key).toBe(null)
+ expect(element.ref).toBe(null)
+ expect(element.props).toEqual({foo: '56'})
+ })
+
+ it('ignores key and ref warning getters', () => {
+ const elementA = React.createElement('div')
+ const elementB = React.createElement('div', elementA.props)
+ expect(elementB.key).toBe(null)
+ expect(elementB.ref).toBe(null)
+ })
+
+ it('coerces the key to a string', () => {
+ const element = React.createElement(ComponentFC, {
+ key: 12,
+ foo: '56',
+ })
+ expect(element.type).toBe(ComponentFC)
+ expect(element.key).toBe('12')
+ expect(element.ref).toBe(null)
+ expect(element.props).toEqual({foo: '56'})
+ })
+
+ // it('preserves the owner on the element', () => {
+ // let element;
+
+ // function Wrapper() {
+ // element = React.createElement(ComponentFC);
+ // return element;
+ // }
+
+ // const instance = ReactTestUtils.renderIntoDocument(
+ // React.createElement(Wrapper)
+ // );
+ // expect(element._owner.stateNode).toBe(instance);
+ // });
+
+ it('merges an additional argument onto the children prop', () => {
+ const a = 1;
+ const element = React.createElement(
+ ComponentFC,
+ {
+ children: 'text'
+ },
+ a
+ );
+ expect(element.props.children).toBe(a);
+ });
+
+ it('does not override children if no rest args are provided', () => {
+ const element = React.createElement(ComponentFC, {
+ children: 'text',
+ })
+ expect(element.props.children).toBe('text')
+ })
+
+ it('overrides children if null is provided as an argument', () => {
+ const element = React.createElement(
+ ComponentFC,
+ {
+ children: 'text'
+ },
+ null
+ );
+ expect(element.props.children).toBe(null);
+ });
+
+ it('merges rest arguments onto the children prop in an array', () => {
+ const a = 1;
+ const b = 2;
+ const c = 3;
+ const element = React.createElement(ComponentFC, null, a, b, c);
+ expect(element.props.children).toEqual([1, 2, 3]);
+ });
+
+ // // NOTE: We're explicitly not using JSX here. This is intended to test
+ // // classic JS without JSX.
+ it('allows static methods to be called using the type property', () => {
+ function StaticMethodComponent() {
+ return React.createElement('div')
+ }
+
+ StaticMethodComponent.someStaticMethod = () => 'someReturnValue'
+
+ const element = React.createElement(StaticMethodComponent)
+ expect(element.type.someStaticMethod()).toBe('someReturnValue')
+ })
+
+ // // NOTE: We're explicitly not using JSX here. This is intended to test
+ // // classic JS without JSX.
+ it('identifies valid elements', () => {
+ function Component() {
+ return React.createElement('div')
+ }
+
+ expect(React.isValidElement(React.createElement('div'))).toEqual(true)
+ expect(React.isValidElement(React.createElement(Component))).toEqual(true)
+
+ expect(React.isValidElement(null)).toEqual(false)
+ expect(React.isValidElement(true)).toEqual(false)
+ expect(React.isValidElement({})).toEqual(false)
+ expect(React.isValidElement('string')).toEqual(false)
+ expect(React.isValidElement(Component)).toEqual(false)
+ expect(React.isValidElement({type: 'div', props: {}})).toEqual(false)
+
+ const jsonElement = JSON.stringify(React.createElement('div'))
+ expect(React.isValidElement(JSON.parse(jsonElement))).toBe(true)
+ })
+
+ // // NOTE: We're explicitly not using JSX here. This is intended to test
+ // // classic JS without JSX.
+ it('is indistinguishable from a plain object', () => {
+ const element = React.createElement('div', {className: 'foo'})
+ const object = {}
+ expect(element.constructor).toBe(object.constructor)
+ })
+
+ it('does not warn for NaN props', () => {
+ function Test() {
+ return
+ }
+
+ const test = ReactTestUtils.renderIntoDocument()
+ expect(test.props.value).toBeNaN()
+ })
+
+ // // NOTE: We're explicitly not using JSX here. This is intended to test
+ // // classic JS without JSX.
+ it('identifies elements, but not JSON, if Symbols are supported', () => {
+ // Rudimentary polyfill
+ // Once all jest engines support Symbols natively we can swap this to test
+ // WITH native Symbols by default.
+ const REACT_ELEMENT_TYPE = function () {
+ } // fake Symbol
+ const OTHER_SYMBOL = function () {
+ } // another fake Symbol
+ global.Symbol = function (name) {
+ return OTHER_SYMBOL
+ }
+ global.Symbol.for = function (key) {
+ if (key === 'react.element') {
+ return REACT_ELEMENT_TYPE
+ }
+ return OTHER_SYMBOL
+ }
+
+ jest.resetModules()
+
+ React = require('../../dist/react')
+
+ function Component() {
+ return React.createElement('div')
+ }
+
+ expect(React.isValidElement(React.createElement('div'))).toEqual(true)
+ expect(React.isValidElement(React.createElement(Component))).toEqual(true)
+
+ expect(React.isValidElement(null)).toEqual(false)
+ expect(React.isValidElement(true)).toEqual(false)
+ expect(React.isValidElement({})).toEqual(false)
+ expect(React.isValidElement('string')).toEqual(false)
+
+ expect(React.isValidElement(Component)).toEqual(false)
+ expect(React.isValidElement({type: 'div', props: {}})).toEqual(false)
+
+ const jsonElement = JSON.stringify(React.createElement('div'))
+ // ignore this test
+ // expect(React.isValidElement(JSON.parse(jsonElement))).toBe(false);
})
- expect(element.props.children).toBe('text')
- })
-
- // it('overrides children if null is provided as an argument', () => {
- // const element = React.createElement(
- // ComponentFC,
- // {
- // children: 'text'
- // },
- // null
- // );
- // expect(element.props.children).toBe(null);
- // });
-
- // it('merges rest arguments onto the children prop in an array', () => {
- // const a = 1;
- // const b = 2;
- // const c = 3;
- // const element = React.createElement(ComponentFC, null, a, b, c);
- // expect(element.props.children).toEqual([1, 2, 3]);
- // });
-
- // // NOTE: We're explicitly not using JSX here. This is intended to test
- // // classic JS without JSX.
- it('allows static methods to be called using the type property', () => {
- function StaticMethodComponent() {
- return React.createElement('div')
- }
-
- StaticMethodComponent.someStaticMethod = () => 'someReturnValue'
-
- const element = React.createElement(StaticMethodComponent)
- expect(element.type.someStaticMethod()).toBe('someReturnValue')
- })
-
- // // NOTE: We're explicitly not using JSX here. This is intended to test
- // // classic JS without JSX.
- it('identifies valid elements', () => {
- function Component() {
- return React.createElement('div')
- }
-
- expect(React.isValidElement(React.createElement('div'))).toEqual(true)
- expect(React.isValidElement(React.createElement(Component))).toEqual(true)
-
- expect(React.isValidElement(null)).toEqual(false)
- expect(React.isValidElement(true)).toEqual(false)
- expect(React.isValidElement({})).toEqual(false)
- expect(React.isValidElement('string')).toEqual(false)
- expect(React.isValidElement(Component)).toEqual(false)
- expect(React.isValidElement({type: 'div', props: {}})).toEqual(false)
-
- const jsonElement = JSON.stringify(React.createElement('div'))
- expect(React.isValidElement(JSON.parse(jsonElement))).toBe(true)
- })
-
- // // NOTE: We're explicitly not using JSX here. This is intended to test
- // // classic JS without JSX.
- it('is indistinguishable from a plain object', () => {
- const element = React.createElement('div', {className: 'foo'})
- const object = {}
- expect(element.constructor).toBe(object.constructor)
- })
-
- it('does not warn for NaN props', () => {
- function Test() {
- return
- }
-
- const test = ReactTestUtils.renderIntoDocument()
- expect(test.props.value).toBeNaN()
- })
-
- // // NOTE: We're explicitly not using JSX here. This is intended to test
- // // classic JS without JSX.
- it('identifies elements, but not JSON, if Symbols are supported', () => {
- // Rudimentary polyfill
- // Once all jest engines support Symbols natively we can swap this to test
- // WITH native Symbols by default.
- const REACT_ELEMENT_TYPE = function () {} // fake Symbol
- const OTHER_SYMBOL = function () {} // another fake Symbol
- global.Symbol = function (name) {
- return OTHER_SYMBOL
- }
- global.Symbol.for = function (key) {
- if (key === 'react.element') {
- return REACT_ELEMENT_TYPE
- }
- return OTHER_SYMBOL
- }
-
- jest.resetModules()
-
- React = require('../../dist/react')
-
- function Component() {
- return React.createElement('div')
- }
-
- expect(React.isValidElement(React.createElement('div'))).toEqual(true)
- expect(React.isValidElement(React.createElement(Component))).toEqual(true)
-
- expect(React.isValidElement(null)).toEqual(false)
- expect(React.isValidElement(true)).toEqual(false)
- expect(React.isValidElement({})).toEqual(false)
- expect(React.isValidElement('string')).toEqual(false)
-
- expect(React.isValidElement(Component)).toEqual(false)
- expect(React.isValidElement({type: 'div', props: {}})).toEqual(false)
-
- const jsonElement = JSON.stringify(React.createElement('div'))
- // ignore this test
- // expect(React.isValidElement(JSON.parse(jsonElement))).toBe(false);
- })
})
diff --git a/examples/hello-world/src/App.tsx b/examples/hello-world/src/App.tsx
index cbe2731..84830df 100644
--- a/examples/hello-world/src/App.tsx
+++ b/examples/hello-world/src/App.tsx
@@ -1,26 +1,33 @@
import {useState} from 'react'
-
function App() {
const [num, updateNum] = useState(0);
- const isOdd = num % 2;
+ const isOdd = num % 2 === 1;
+
+ const before = [
+