describe('Greeter', () => { it('renders normally', () => { // Render a checkbox with label in the document const greeter = TestUtils.renderIntoDocument( <Greeter name="Galaxy" /> ); const greeterNode = ReactDOM.findDOMNode(greeter); expect(greeterNode).toBeTruthy(); }); });
it("user is null", () => { // Render a checkbox with label in the document const user = null; const card = TestUtils.renderIntoDocument(<Card user={user} />); const cardNode = ReactDOM.findDOMNode(card); expect(TestUtils.isDOMComponent(cardNode)).toEqual(true) });
function createControl (props = {}) { loadOptions = props.loadOptions || sinon.stub(); asyncInstance = TestUtils.renderIntoDocument( <Select.Async autoload={false} openOnFocus loadOptions={loadOptions} {...props} /> ); asyncNode = ReactDOM.findDOMNode(asyncInstance); findAndFocusInputControl(); }
// For older version of Jest, turn automocking off by uncommenting the next line // jest.dontMock('react') // jest.dontMock('react-dom') describe('HelloWorld', ()=>{ const TestUtils = require('react-dom/test-utils') const React = require('react') it('has a div', (done)=>{ class HelloWorld extends React.Component { render() { return <div>{this.props.children}</div> } } let hello = TestUtils.renderIntoDocument(<HelloWorld>Hello Node!</HelloWorld>) expect( TestUtils.scryRenderedDOMComponentsWithTag(hello, 'div').length).toBe(1) console.log('found this many divs: ', TestUtils.scryRenderedDOMComponentsWithTag(hello, 'div').length) done() }) })
var createControlWithWrapper = (props, options) => { options = options || {}; if (options.wireUpOnChangeToValue) { onChange = sinon.spy(setValueProp); } else { onChange = sinon.spy(); } onInputChange = sinon.spy(); wrapper = TestUtils.renderIntoDocument( <PropsWrapper childComponent={Select} onChange={onChange} onInputChange={onInputChange} {...props} /> ); instance = wrapper.getChild(); if (options.initialFocus !== false) { findAndFocusInputControl(); } return wrapper; }
function createControl (props = {}) { props.options = props.options || defaultOptions; creatableInstance = TestUtils.renderIntoDocument( <Select.Creatable {...props} /> ); creatableNode = ReactDOM.findDOMNode(creatableInstance); innerSelectInstance = creatableInstance.select; findAndFocusInputControl(); }
it("Change value", () => { let actual = "not changed"; const testFunc = value => { actual = value; }; const header = TestUtils.renderIntoDocument( <Header inputHandler={testFunc} token={"initial_token"} /> ); const headerNode = ReactDOM.findDOMNode(header); const inputTag = headerNode.getElementsByTagName("input")[0]; TestUtils.Simulate.change(inputTag, { target: { value: "changed" } }); expect(actual).toEqual("changed"); expect(inputTag.value).toEqual("initial_token"); });
var createControl = (props, options) => { options = options || {}; onChange = sinon.spy(); onInputChange = sinon.spy(); // Render an instance of the component instance = TestUtils.renderIntoDocument( <Select onChange={onChange} onInputChange={onInputChange} {...props} /> ); if (options.initialFocus !== false) { findAndFocusInputControl(); } return instance; }
describe('App', () => { test('Render the main app without crashing', () => { renderIntoDocument(<App />) }) })
describe('HelloWorld', () => { const TestUtils = require('react-dom/test-utils'); const React = require('react'); it('has props', done => { class HelloWorld extends React.Component { render() { return <div>{this.props.children}</div> } } let hello = TestUtils.renderIntoDocument( <HelloWorld>Hello Node!</HelloWorld> ); expect(hello.props).toBeDefined(); console.log('my hello props:', hello.props); done(); }); });
describe('HelloWorld', () => { const TestUtils = require('react-dom/test-utils'); const React = require('react'); it('has a div', done => { class HelloWorld extends React.Component { render() { return <div>{this.props.children}</div> } } let hello = TestUtils.renderIntoDocument( <HelloWorld>Hello Node!</HelloWorld> ); let test = TestUtils.scryRenderedDOMComponentsWithTag(hello, 'div').length; expect(test).toBe(1); console.log('found this many divs:', test); done(); }) });
it("user is not null", () => { // Render a checkbox with label in the document const user = { login: "test user", name: "I'm a test", avatarUrl: "https://test.dev" }; const card = TestUtils.renderIntoDocument(<Card user={user} />); const cardNode = ReactDOM.findDOMNode(card); expect(TestUtils.isDOMComponent(cardNode)).toEqual(true) });
describe('HelloWorld', () => { const TestUtils = require('react-dom/test-utils'); const React = require('react'); it('has props', done => { class HelloWorld extends React.Component { render() { return <div>{this.props.children}</div> } } let hello = TestUtils.renderIntoDocument( <HelloWorld>Hello Node!</HelloWorld> ); expect(hello.props).toBeDefined(); console.log('my hello props:', hello.props); done(); }); });
// For older version of Jest, turn automocking off by uncommenting the next line // jest.dontMock('react') // jest.dontMock('react-dom') describe('HelloWorld', ()=>{ const TestUtils = require('react-dom/test-utils') const React = require('react') it('has props', (done)=>{ class HelloWorld extends React.Component { render() { return <div>{this.props.children}</div> } } let hello = TestUtils.renderIntoDocument(<HelloWorld>Hello Node!</HelloWorld>) expect(hello.props).toBeDefined() console.log('my hello props:', hello.props) // my div: Hello Node! done() }) })
describe('HelloWorld', () => { const TestUtils = require('react-dom/test-utils'); const React = require('react'); it('has a div', done => { class HelloWorld extends React.Component { render() { return <div>{this.props.children}</div> } } let hello = TestUtils.renderIntoDocument( <HelloWorld>Hello Node!</HelloWorld> ); let test = TestUtils.scryRenderedDOMComponentsWithTag(hello, 'div').length; expect(test).toBe(1); console.log('found this many divs:', test); done(); }) });