Best JavaScript code snippet using playwright-internal
react-test-renderer-shallow.js
Source:react-test-renderer-shallow.js
...228}229var checkPropTypes_1 = checkPropTypes;230function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }231var ReactShallowRenderer = function () {232 function ReactShallowRenderer() {233 _classCallCheck(this, ReactShallowRenderer);234 this._context = null;235 this._element = null;236 this._instance = null;237 this._newState = null;238 this._rendered = null;239 this._rendering = false;240 this._forcedUpdate = false;241 this._updater = new Updater(this);242 }243 ReactShallowRenderer.prototype.getMountedInstance = function getMountedInstance() {244 return this._instance;245 };246 ReactShallowRenderer.prototype.getRenderOutput = function getRenderOutput() {247 return this._rendered;248 };249 ReactShallowRenderer.prototype.render = function render(element) {250 var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : emptyObject_1;251 !React.isValidElement(element) ? reactProdInvariant('12', typeof element === 'function' ? ' Instead of passing a component class, make sure to instantiate ' + 'it by passing it to React.createElement.' : '') : void 0;252 // Show a special message for host elements since it's a common case.253 !(typeof element.type !== 'string') ? reactProdInvariant('13', element.type) : void 0;254 !(isForwardRef(element) || typeof element.type === 'function') ? reactProdInvariant('249', Array.isArray(element.type) ? 'array' : element.type === null ? 'null' : typeof element.type) : void 0;255 if (this._rendering) {256 return;257 }258 this._rendering = true;259 this._element = element;260 this._context = getMaskedContext(element.type.contextTypes, context);261 if (this._instance) {262 this._updateClassComponent(element, this._context);263 } else {264 if (isForwardRef(element)) {265 this._rendered = element.type.render(element.props, element.ref);266 } else if (shouldConstruct(element.type)) {267 this._instance = new element.type(element.props, this._context, this._updater);268 this._updateStateFromStaticLifecycle(element.props);269 if (element.type.hasOwnProperty('contextTypes')) {270 currentlyValidatingElement = element;271 checkPropTypes_1(element.type.contextTypes, this._context, 'context', getName(element.type, this._instance), getStackAddendum);272 currentlyValidatingElement = null;273 }274 this._mountClassComponent(element, this._context);275 } else {276 this._rendered = element.type(element.props, this._context);277 }278 }279 this._rendering = false;280 this._updater._invokeCallbacks();281 return this.getRenderOutput();282 };283 ReactShallowRenderer.prototype.unmount = function unmount() {284 if (this._instance) {285 if (typeof this._instance.componentWillUnmount === 'function') {286 this._instance.componentWillUnmount();287 }288 }289 this._context = null;290 this._element = null;291 this._newState = null;292 this._rendered = null;293 this._instance = null;294 };295 ReactShallowRenderer.prototype._mountClassComponent = function _mountClassComponent(element, context) {296 this._instance.context = context;297 this._instance.props = element.props;298 this._instance.state = this._instance.state || null;299 this._instance.updater = this._updater;300 if (typeof this._instance.UNSAFE_componentWillMount === 'function' || typeof this._instance.componentWillMount === 'function') {301 var beforeState = this._newState;302 // In order to support react-lifecycles-compat polyfilled components,303 // Unsafe lifecycles should not be invoked for components using the new APIs.304 if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {305 if (typeof this._instance.componentWillMount === 'function') {306 this._instance.componentWillMount();307 }308 if (typeof this._instance.UNSAFE_componentWillMount === 'function') {309 this._instance.UNSAFE_componentWillMount();310 }311 }312 // setState may have been called during cWM313 if (beforeState !== this._newState) {314 this._instance.state = this._newState || emptyObject_1;315 }316 }317 this._rendered = this._instance.render();318 // Intentionally do not call componentDidMount()319 // because DOM refs are not available.320 };321 ReactShallowRenderer.prototype._updateClassComponent = function _updateClassComponent(element, context) {322 var props = element.props,323 type = element.type;324 var oldState = this._instance.state || emptyObject_1;325 var oldProps = this._instance.props;326 if (oldProps !== props) {327 // In order to support react-lifecycles-compat polyfilled components,328 // Unsafe lifecycles should not be invoked for components using the new APIs.329 if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {330 if (typeof this._instance.componentWillReceiveProps === 'function') {331 this._instance.componentWillReceiveProps(props, context);332 }333 if (typeof this._instance.UNSAFE_componentWillReceiveProps === 'function') {334 this._instance.UNSAFE_componentWillReceiveProps(props, context);335 }336 }337 }338 this._updateStateFromStaticLifecycle(props);339 // Read state after cWRP in case it calls setState340 var state = this._newState || oldState;341 var shouldUpdate = true;342 if (this._forcedUpdate) {343 shouldUpdate = true;344 this._forcedUpdate = false;345 } else if (typeof this._instance.shouldComponentUpdate === 'function') {346 shouldUpdate = !!this._instance.shouldComponentUpdate(props, state, context);347 } else if (type.prototype && type.prototype.isPureReactComponent) {348 shouldUpdate = !shallowEqual_1(oldProps, props) || !shallowEqual_1(oldState, state);349 }350 if (shouldUpdate) {351 // In order to support react-lifecycles-compat polyfilled components,352 // Unsafe lifecycles should not be invoked for components using the new APIs.353 if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {354 if (typeof this._instance.componentWillUpdate === 'function') {355 this._instance.componentWillUpdate(props, state, context);356 }357 if (typeof this._instance.UNSAFE_componentWillUpdate === 'function') {358 this._instance.UNSAFE_componentWillUpdate(props, state, context);359 }360 }361 }362 this._instance.context = context;363 this._instance.props = props;364 this._instance.state = state;365 if (shouldUpdate) {366 this._rendered = this._instance.render();367 }368 // Intentionally do not call componentDidUpdate()369 // because DOM refs are not available.370 };371 ReactShallowRenderer.prototype._updateStateFromStaticLifecycle = function _updateStateFromStaticLifecycle(props) {372 var type = this._element.type;373 if (typeof type.getDerivedStateFromProps === 'function') {374 var oldState = this._newState || this._instance.state;375 var partialState = type.getDerivedStateFromProps.call(null, props, oldState);376 if (partialState != null) {377 var newState = _assign({}, oldState, partialState);378 this._instance.state = this._newState = newState;379 }380 }381 };382 return ReactShallowRenderer;383}();384ReactShallowRenderer.createRenderer = function () {385 return new ReactShallowRenderer();386};387var Updater = function () {388 function Updater(renderer) {389 _classCallCheck(this, Updater);390 this._renderer = renderer;391 this._callbacks = [];392 }393 Updater.prototype._enqueueCallback = function _enqueueCallback(callback, publicInstance) {394 if (typeof callback === 'function' && publicInstance) {395 this._callbacks.push({396 callback: callback,397 publicInstance: publicInstance398 });399 }...
table.test.js
Source:table.test.js
1/*2 * Licensed to Elasticsearch B.V. under one or more contributor3 * license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright5 * ownership. Elasticsearch B.V. licenses this file to you under6 * the Apache License, Version 2.0 (the "License"); you may7 * not use this file except in compliance with the License.8 * You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19import React from 'react';20import { shallow } from 'enzyme';21import { shallowWithIntl } from 'test_utils/enzyme_helpers';22import { TableComponent } from '../table';23import { keyCodes } from '@elastic/eui';24const indexPattern = {};25const items = [{ value: 'tim*' }];26describe('Table', () => {27 it('should render normally', async () => {28 const component = shallowWithIntl(29 <TableComponent30 indexPattern={indexPattern}31 items={items}32 deleteFilter={() => {}}33 fieldWildcardMatcher={() => {}}34 saveFilter={() => {}}35 isSaving={true}36 />37 );38 expect(component).toMatchSnapshot();39 });40 it('should render filter matches', async () => {41 const component = shallowWithIntl(42 <TableComponent43 indexPattern={{44 getNonScriptedFields: () => [{ name: 'time' }, { name: 'value' }],45 }}46 items={items}47 deleteFilter={() => {}}48 fieldWildcardMatcher={filter => field => field.includes(filter[0])}49 saveFilter={() => {}}50 isSaving={false}51 />52 );53 const matchesTableCell = shallow(54 component.prop('columns')[1].render('tim', { clientId: 1 })55 );56 expect(matchesTableCell).toMatchSnapshot();57 });58 describe('editing', () => {59 const saveFilter = jest.fn();60 const clientId = 1;61 let component;62 beforeEach(() => {63 component = shallowWithIntl(64 <TableComponent65 indexPattern={indexPattern}66 items={items}67 deleteFilter={() => {}}68 fieldWildcardMatcher={() => {}}69 saveFilter={saveFilter}70 isSaving={false}71 />72 );73 });74 it('should show an input field', () => {75 // Start the editing process76 const editingComponent = shallow(77 // Wrap in a div because: https://github.com/airbnb/enzyme/issues/121378 <div>79 {component.prop('columns')[2].render({ clientId, value: 'tim*' })}80 </div>81 );82 editingComponent83 .find('EuiButtonIcon')84 .at(1)85 .simulate('click');86 // Ensure the state change propagates87 component.update();88 // Ensure the table cell switches to an input89 const filterNameTableCell = shallow(90 component.prop('columns')[0].render('tim*', { clientId })91 );92 expect(filterNameTableCell).toMatchSnapshot();93 });94 it('should show a save button', () => {95 // Start the editing process96 const editingComponent = shallow(97 // Fixes: Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.98 <div>99 {component.prop('columns')[2].render({ clientId, value: 'tim*' })}100 </div>101 );102 editingComponent103 .find('EuiButtonIcon')104 .at(1)105 .simulate('click');106 // Ensure the state change propagates107 component.update();108 // Verify save button109 const saveTableCell = shallow(110 // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.111 <div>112 {component.prop('columns')[2].render({ clientId, value: 'tim*' })}113 </div>114 );115 expect(saveTableCell).toMatchSnapshot();116 });117 it('should update the matches dynamically as input value is changed', () => {118 const localComponent = shallowWithIntl(119 <TableComponent120 indexPattern={{121 getNonScriptedFields: () => [{ name: 'time' }, { name: 'value' }],122 }}123 items={items}124 deleteFilter={() => {}}125 fieldWildcardMatcher={query => () => {126 return query.includes('time*');127 }}128 saveFilter={saveFilter}129 isSaving={false}130 />131 );132 // Start the editing process133 const editingComponent = shallow(134 // Fixes: Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.135 <div>136 {localComponent137 .prop('columns')[2]138 .render({ clientId, value: 'tim*' })}139 </div>140 );141 editingComponent142 .find('EuiButtonIcon')143 .at(1)144 .simulate('click');145 // Update the value146 localComponent.setState({ editingFilterValue: 'time*' });147 // Ensure the state change propagates148 localComponent.update();149 // Verify updated matches150 const matchesTableCell = shallow(151 // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.152 <div>153 {localComponent.prop('columns')[1].render('tim*', { clientId })}154 </div>155 );156 expect(matchesTableCell).toMatchSnapshot();157 });158 it('should exit on save', () => {159 // Change the value to something else160 component.setState({161 editingFilterId: clientId,162 editingFilterValue: 'ti*',163 });164 // Click the save button165 const editingComponent = shallow(166 // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.167 <div>168 {component.prop('columns')[2].render({ clientId, value: 'tim*' })}169 </div>170 );171 editingComponent172 .find('EuiButtonIcon')173 .at(0)174 .simulate('click');175 // Ensure we call saveFilter properly176 expect(saveFilter).toBeCalledWith({177 filterId: clientId,178 newFilterValue: 'ti*',179 });180 // Ensure the state is properly reset181 expect(component.state('editingFilterId')).toBe(null);182 });183 });184 it('should allow deletes', () => {185 const deleteFilter = jest.fn();186 const component = shallowWithIntl(187 <TableComponent188 indexPattern={indexPattern}189 items={items}190 deleteFilter={deleteFilter}191 fieldWildcardMatcher={() => {}}192 saveFilter={() => {}}193 isSaving={false}194 />195 );196 // Click the delete button197 const deleteCellComponent = shallow(198 // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.199 <div>200 {component.prop('columns')[2].render({ clientId: 1, value: 'tim*' })}201 </div>202 );203 deleteCellComponent204 .find('EuiButtonIcon')205 .at(0)206 .simulate('click');207 expect(deleteFilter).toBeCalled();208 });209 it('should save when in edit mode and the enter key is pressed', () => {210 const saveFilter = jest.fn();211 const clientId = 1;212 const component = shallowWithIntl(213 <TableComponent214 indexPattern={indexPattern}215 items={items}216 deleteFilter={() => {}}217 fieldWildcardMatcher={() => {}}218 saveFilter={saveFilter}219 isSaving={false}220 />221 );222 // Start the editing process223 const editingComponent = shallow(224 // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.225 <div>226 {component.prop('columns')[2].render({ clientId, value: 'tim*' })}227 </div>228 );229 editingComponent230 .find('EuiButtonIcon')231 .at(1)232 .simulate('click');233 // Ensure the state change propagates234 component.update();235 // Get the rendered input cell236 const filterNameTableCell = shallow(237 // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.238 <div>{component.prop('columns')[0].render('tim*', { clientId })}</div>239 );240 // Press the enter key241 filterNameTableCell242 .find('EuiFieldText')243 .simulate('keydown', { keyCode: keyCodes.ENTER });244 expect(saveFilter).toBeCalled();245 // It should reset246 expect(component.state('editingFilterId')).toBe(null);247 });248 it('should cancel when in edit mode and the esc key is pressed', () => {249 const saveFilter = jest.fn();250 const clientId = 1;251 const component = shallowWithIntl(252 <TableComponent253 indexPattern={indexPattern}254 items={items}255 deleteFilter={() => {}}256 fieldWildcardMatcher={() => {}}257 saveFilter={saveFilter}258 isSaving={false}259 />260 );261 // Start the editing process262 const editingComponent = shallow(263 // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.264 <div>265 {component.prop('columns')[2].render({ clientId, value: 'tim*' })}266 </div>267 );268 editingComponent269 .find('EuiButtonIcon')270 .at(1)271 .simulate('click');272 // Ensure the state change propagates273 component.update();274 // Get the rendered input cell275 const filterNameTableCell = shallow(276 // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.277 <div>{component.prop('columns')[0].render('tim*', { clientId })}</div>278 );279 // Press the enter key280 filterNameTableCell281 .find('EuiFieldText')282 .simulate('keydown', { keyCode: keyCodes.ESCAPE });283 expect(saveFilter).not.toBeCalled();284 // It should reset285 expect(component.state('editingFilterId')).toBe(null);286 });...
react-test-renderer-shallow.development.js
Source:react-test-renderer-shallow.development.js
...29var _extends = objectAssign$1 || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };30function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }31var ReactDebugCurrentFrame = ReactGlobalSharedState_1.ReactDebugCurrentFrame;32var ReactShallowRenderer = function () {33 function ReactShallowRenderer() {34 _classCallCheck(this, ReactShallowRenderer);35 this._context = null;36 this._element = null;37 this._instance = null;38 this._newState = null;39 this._rendered = null;40 this._rendering = false;41 this._updater = new Updater(this);42 }43 ReactShallowRenderer.prototype.getMountedInstance = function getMountedInstance() {44 return this._instance;45 };46 ReactShallowRenderer.prototype.getRenderOutput = function getRenderOutput() {47 return this._rendered;48 };49 ReactShallowRenderer.prototype.render = function render(element) {50 var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : emptyObject;51 !react.isValidElement(element) ? invariant(false, 'ReactShallowRenderer render(): Invalid component element.%s', typeof element === 'function' ? ' Instead of passing a component class, make sure to instantiate ' + 'it by passing it to React.createElement.' : '') : void 0;52 !(typeof element.type !== 'string') ? invariant(false, 'ReactShallowRenderer render(): Shallow rendering works only with custom components, not primitives (%s). Instead of calling `.render(el)` and inspecting the rendered output, look at `el.props` directly instead.', element.type) : void 0;53 if (this._rendering) {54 return;55 }56 this._rendering = true;57 this._element = element;58 this._context = context;59 if (this._instance) {60 this._updateClassComponent(element.props, context);61 } else {62 if (shouldConstruct(element.type)) {63 this._instance = new element.type(element.props, context, this._updater);64 if (element.type.hasOwnProperty('contextTypes')) {65 ReactDebugCurrentFrame.element = element;66 checkPropTypes(element.type.contextTypes, context, 'context', getName(element.type, this._instance), ReactDebugCurrentFrame.getStackAddendum);67 ReactDebugCurrentFrame.element = null;68 }69 this._mountClassComponent(element.props, context);70 } else {71 this._rendered = element.type(element.props, context);72 }73 }74 this._rendering = false;75 return this.getRenderOutput();76 };77 ReactShallowRenderer.prototype.unmount = function unmount() {78 if (this._instance) {79 if (typeof this._instance.componentWillUnmount === 'function') {80 this._instance.componentWillUnmount();81 }82 }83 this._context = null;84 this._element = null;85 this._newState = null;86 this._rendered = null;87 this._instance = null;88 };89 ReactShallowRenderer.prototype._mountClassComponent = function _mountClassComponent(props, context) {90 this._instance.context = context;91 this._instance.props = props;92 this._instance.state = this._instance.state || emptyObject;93 this._instance.updater = this._updater;94 if (typeof this._instance.componentWillMount === 'function') {95 var beforeState = this._newState;96 this._instance.componentWillMount();97 // setState may have been called during cWM98 if (beforeState !== this._newState) {99 this._instance.state = this._newState || emptyObject;100 }101 }102 this._rendered = this._instance.render();103 // Calling cDU might lead to problems with host component references.104 // Since our components aren't really mounted, refs won't be available.105 // if (typeof this._instance.componentDidMount === 'function') {106 // this._instance.componentDidMount();107 // }108 };109 ReactShallowRenderer.prototype._updateClassComponent = function _updateClassComponent(props, context) {110 var oldProps = this._instance.props;111 var oldState = this._instance.state;112 if (oldProps !== props && typeof this._instance.componentWillReceiveProps === 'function') {113 this._instance.componentWillReceiveProps(props);114 }115 // Read state after cWRP in case it calls setState116 // Fallback to previous instance state to support rendering React.cloneElement()117 var state = this._newState || this._instance.state || emptyObject;118 if (typeof this._instance.shouldComponentUpdate === 'function') {119 if (this._instance.shouldComponentUpdate(props, state, context) === false) {120 this._instance.context = context;121 this._instance.props = props;122 this._instance.state = state;123 return;124 }125 }126 if (typeof this._instance.componentWillUpdate === 'function') {127 this._instance.componentWillUpdate(props, state, context);128 }129 this._instance.context = context;130 this._instance.props = props;131 this._instance.state = state;132 this._rendered = this._instance.render();133 // The 15.x shallow renderer triggered cDU for setState() calls only.134 if (oldState !== state && typeof this._instance.componentDidUpdate === 'function') {135 this._instance.componentDidUpdate(oldProps, oldState);136 }137 };138 return ReactShallowRenderer;139}();140ReactShallowRenderer.createRenderer = function () {141 return new ReactShallowRenderer();142};143var Updater = function () {144 function Updater(renderer) {145 _classCallCheck(this, Updater);146 this._renderer = renderer;147 }148 Updater.prototype.isMounted = function isMounted(publicInstance) {149 return !!this._renderer._element;150 };151 Updater.prototype.enqueueForceUpdate = function enqueueForceUpdate(publicInstance, callback, callerName) {152 this._renderer.render(this._renderer._element, this._renderer._context);153 };154 Updater.prototype.enqueueReplaceState = function enqueueReplaceState(publicInstance, completeState, callback, callerName) {155 this._renderer._newState = completeState;...
ReactShallowRenderer.js
Source:ReactShallowRenderer.js
...67 renderer._render(element, transaction, context);68 ReactUpdates.ReactReconcileTransaction.release(transaction);69}70var ReactShallowRenderer = function () {71 function ReactShallowRenderer() {72 _classCallCheck(this, ReactShallowRenderer);73 this._instance = null;74 }75 ReactShallowRenderer.prototype.getMountedInstance = function getMountedInstance() {76 return this._instance ? this._instance._instance : null;77 };78 ReactShallowRenderer.prototype.render = function render(element, context) {79 // Ensure we've done the default injections. This might not be true in the80 // case of a simple test that only requires React and the TestUtils in81 // conjunction with an inline-requires transform.82 injectDefaults();83 !React.isValidElement(element) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactShallowRenderer render(): Invalid component element.%s', typeof element === 'function' ? ' Instead of passing a component class, make sure to instantiate ' + 'it by passing it to React.createElement.' : '') : _prodInvariant('12', typeof element === 'function' ? ' Instead of passing a component class, make sure to instantiate ' + 'it by passing it to React.createElement.' : '') : void 0;84 !(typeof element.type !== 'string') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactShallowRenderer render(): Shallow rendering works only with custom components, not primitives (%s). Instead of calling `.render(el)` and inspecting the rendered output, look at `el.props` directly instead.', element.type) : _prodInvariant('13', element.type) : void 0;85 if (!context) {86 context = emptyObject;87 }88 ReactUpdates.batchedUpdates(_batchedRender, this, element, context);89 return this.getRenderOutput();90 };91 ReactShallowRenderer.prototype.getRenderOutput = function getRenderOutput() {92 return this._instance && this._instance._renderedComponent && this._instance._renderedComponent._renderedOutput || null;93 };94 ReactShallowRenderer.prototype.unmount = function unmount() {95 if (this._instance) {96 ReactReconciler.unmountComponent(this._instance, false);97 }98 };99 ReactShallowRenderer.prototype.unstable_batchedUpdates = function unstable_batchedUpdates(callback, bookkeeping) {100 // This is used by Enzyme for fake-simulating events in shallow mode.101 injectDefaults();102 return ReactUpdates.batchedUpdates(callback, bookkeeping);103 };104 ReactShallowRenderer.prototype._render = function _render(element, transaction, context) {105 if (this._instance) {106 ReactReconciler.receiveComponent(this._instance, element, transaction, context);107 } else {108 var instance = new ShallowComponentWrapper(element);109 ReactReconciler.mountComponent(instance, transaction, null, null, context, 0);110 this._instance = instance;111 }112 };113 return ReactShallowRenderer;114}();115ReactShallowRenderer.createRenderer = function () {116 return new ReactShallowRenderer();117};...
VideoListSpec.jsx
Source:VideoListSpec.jsx
...8 it('should be a stateless functional component', function() {9 expect(React.Component.isPrototypeOf(VideoList)).to.be.false;10 });11 it('should render one `VideoListEntry` when given one video', function() {12 var shallowRenderer = new ReactShallowRenderer();13 var oneFakeVideo = window.fakeVideoData.slice(-1);14 shallowRenderer.render(15 <VideoList videos={oneFakeVideo} />16 );17 var videoList = shallowRenderer.getRenderOutput();18 expect(videoList.props.children).to.have.length(1);19 videoList.props.children.forEach(child => expect(child.type).to.equal(VideoListEntry));20 });21 it('should render three `VideoListEntry` when given three videos', function() {22 var shallowRenderer = new ReactShallowRenderer();23 var threeFakeVideos = window.fakeVideoData.slice(-3);24 shallowRenderer.render(25 <VideoList videos={threeFakeVideos} />26 );27 var videoList = shallowRenderer.getRenderOutput();28 expect(videoList.props.children).to.have.length(3);29 videoList.props.children.forEach(child => expect(child.type).to.equal(VideoListEntry));30 });31 it('should render five `VideoListEntry` when given five videos', function() {32 var shallowRenderer = new ReactShallowRenderer();33 var fiveFakeVideos = window.fakeVideoData.slice(-5);34 shallowRenderer.render(35 <VideoList videos={fiveFakeVideos} />36 );37 var videoList = shallowRenderer.getRenderOutput();38 expect(videoList.props.children).to.have.length(5);39 videoList.props.children.forEach(child => expect(child.type).to.equal(VideoListEntry));40 });...
player.jsx
Source:player.jsx
...4const context = {5 setVideo() {},6};7test('mount', () => {8 const renderer = new ReactShallowRenderer();9 const result = renderer.render(<Player location={{ search: '' }} />, context);10 expect(result.type).toBe('div');11});12test('have search', () => {13 const renderer = new ReactShallowRenderer();14 const result = renderer.render(15 <Player location={{ search: 'https://example.com/index.m3u8' }} />,16 context,17 );18 expect(result.type).toBe('div');...
shallow.js
Source:shallow.js
1/**2 * Copyright (c) 2013-present, Facebook, Inc.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 *7 * @flow8 */9'use strict';10const ReactShallowRenderer = require('./src/ReactShallowRenderer');11// TODO: decide on the top-level export form.12// This is hacky but makes it work with both Rollup and Jest.13module.exports = ReactShallowRenderer.default14 ? ReactShallowRenderer.default...
createShallowComponent.js
Source:createShallowComponent.js
1import React from 'react';2import ReactShallowRenderer from 'react-test-renderer/shallow';3function createComponent(jsx) {4 const renderer = new ReactShallowRenderer();5 renderer.render(jsx);6 return renderer.getRenderOutput();7}...
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const reactShallowRenderer = await page._reactShallowRenderer();7 const html = await reactShallowRenderer.render('<App />');8 console.log(html);9 await browser.close();10})();
Using AI Code Generation
1const playwright = require('playwright');2const { ReactShallowRenderer } = require('playwright/lib/server/reactShallowRenderer');3const { ReactTestRenderer } = require('playwright/lib/server/reactTestRenderer');4const { ReactTestInstance } = require('playwright/lib/server/reactTestInstance');5(async () => {6 const browser = await playwright.chromium.launch();7 const page = await browser.newPage();8 const renderer = new ReactShallowRenderer(page);9 const root = await renderer.render('body');10 console.log(root.children.length);11 await browser.close();12})();13const playwright = require('playwright');14const { ReactShallowRenderer } = require('playwright/lib/server/reactShallowRenderer');15const { ReactTestRenderer } = require('playwright/lib/server/reactTestRenderer');16const { ReactTestInstance } = require('playwright/lib/server/reactTestInstance');17(async () => {18 const browser = await playwright.chromium.launch();19 const page = await browser.newPage();20 const renderer = new ReactTestRenderer(page);21 const root = await renderer.render('body');22 console.log(root.children.length);23 await browser.close();24})();25const playwright = require('playwright');26const { ReactShallowRenderer } = require('playwright/lib/server/reactShallowRenderer');27const { ReactTestRenderer } = require('playwright/lib/server/reactTestRenderer');28const { ReactTestInstance } = require('playwright/lib/server/reactTestInstance');29(async () => {30 const browser = await playwright.chromium.launch();31 const page = await browser.newPage();32 const renderer = new ReactTestRenderer(page);33 const root = await renderer.render('body');34 const element = root.findByProps({id: 'js-link-box-en'});35 console.log(element.props.id);36 await browser.close();37})();38const playwright = require('playwright');39const { ReactShallowRenderer } =
Using AI Code Generation
1const { ReactShallowRenderer } = require('@playwright/test');2const renderer = new ReactShallowRenderer();3const element = <div>Hello</div>;4renderer.render(element);5const output = renderer.getRenderOutput();6console.log(output);7{ '$$typeof': Symbol(react.element),8 props: { children: 'Hello' },9 _store: {} }
Using AI Code Generation
1const playwright = require('playwright');2const ReactShallowRenderer = require('playwright/lib/internal/reactShallowRenderer').ReactShallowRenderer;3const path = require('path');4(async () => {5 const browser = await playwright.chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 const renderer = new ReactShallowRenderer(page);9 const reactComponent = await renderer.render(path.join(__dirname, './App.js'));10 console.log(reactComponent);11 await browser.close();12})();13import React from 'react';14export default function App() {15 return (16 );17}18{19 props: { children: { type: 'h1', props: { children: 'Welcome to React!' } } }20}21const playwright = require('playwright');22const ReactShallowRenderer = require('playwright/lib/internal/reactShallowRenderer').ReactShallowRenderer;23const path = require('path');24(async () => {25 const browser = await playwright.chromium.launch();26 const context = await browser.newContext();27 const page = await context.newPage();28 const renderer = new ReactShallowRenderer(page);29 const reactComponent = await renderer.render(path.join(__dirname, './App.js'));30 console.log(reactComponent);31 await browser.close();32})();33import React from 'react';34export default function App() {35 return (36 );37}38{39 props: { children: { type: 'h1', props: { children: 'Welcome to React!' } } }40}
Using AI Code Generation
1const { ReactShallowRenderer } = require("@playwright/test");2const { test } = require("@playwright/test");3const { expect } = require("@playwright/test");4const renderer = new ReactShallowRenderer();5test("ReactShallowRenderer", async ({ page }) => {6const component = await renderer.render(page, "Hello, world!");7expect(component.props.children).toBe("Hello, world!");8});9{10"scripts": {11},12"devDependencies": {13}14}
Using AI Code Generation
1const playwright = require('playwright');2const { ReactShallowRenderer } = playwright;3const renderer = new ReactShallowRenderer();4renderer.render(React.createElement('div', null, 'Hello world'));5const output = renderer.getRenderOutput();6console.log(output);7const playwright = require('playwright');8const { ReactShallowRenderer } = playwright;9const renderer = new ReactShallowRenderer();10renderer.render(React.createElement('div', null, 'Hello world'));11const output = renderer.getRenderOutput();12console.log(output);13const playwright = require('playwright');14const { ReactShallowRenderer } = playwright;15const renderer = new ReactShallowRenderer();16renderer.render(React.createElement('div', null, 'Hello world'));17const output = renderer.getRenderOutput();18console.log(output);19const playwright = require('playwright');20const { ReactShallowRenderer } = playwright;21const renderer = new ReactShallowRenderer();22renderer.render(React.createElement('div', null, 'Hello world'));23const output = renderer.getRenderOutput();24console.log(output);25const playwright = require('playwright');26const { ReactShallowRenderer } = playwright;27const renderer = new ReactShallowRenderer();28renderer.render(React.createElement('div', null, 'Hello world'));29const output = renderer.getRenderOutput();30console.log(output);31const playwright = require('playwright');32const { ReactShallowRenderer } = playwright;33const renderer = new ReactShallowRenderer();34renderer.render(React.createElement('div', null, 'Hello world'));35const output = renderer.getRenderOutput();36console.log(output);37const playwright = require('playwright');38const { ReactShallowRenderer } = playwright;39const renderer = new ReactShallowRenderer();40renderer.render(React.createElement('div', null, 'Hello world'));41const output = renderer.getRenderOutput();42console.log(output);43const playwright = require('playwright');44const { ReactShallowRenderer } = playwright;
Using AI Code Generation
1const { ReactShallowRenderer } = require('@playwright/test');2const renderer = new ReactShallowRenderer();3renderer.render(<div>hello</div>);4const output = renderer.getRenderOutput();5console.log(output);6const { test } = require('@playwright/test');7const { ReactShallowRenderer } = require('@playwright/test');8const renderer = new ReactShallowRenderer();9test('test', async ({ page }) => {10 renderer.render(<div>hello</div>);11 const output = renderer.getRenderOutput();12 console.log(output);13});14Element {15 props: { children: 'hello' },16 _store: {}17}18const { test } = require('@playwright/test');19test('test', async ({ page }) => {20 const renderer = new ReactShallowRenderer();21 renderer.render(<div>hello</div>);22 const output = renderer.getRenderOutput();23 console.log(output);24});
Using AI Code Generation
1const { ReactShallowRenderer } = require('playwright');2const renderer = new ReactShallowRenderer();3const { React } = require('playwright');4const { Component } = React;5renderer.render(<Component />);6renderer.getRenderOutput();7renderer.unmount();8renderer.render(<Component />);9renderer.getRenderOutput();10renderer.unmount();11const { ReactShallowRenderer } = require('playwright');12const renderer = new ReactShallowRenderer();13const { React } = require('playwright');14const { Component } = React;15renderer.render(<Component />);16renderer.getRenderOutput();17renderer.unmount();18renderer.render(<Component />);19renderer.getRenderOutput();20renderer.unmount();21const { ReactShallowRenderer } = require('playwright');22const renderer = new ReactShallowRenderer();23const { React } = require('playwright');24const { Component } = React;25renderer.render(<Component />);26renderer.getRenderOutput();27renderer.unmount();28renderer.render(<Component />);29renderer.getRenderOutput();30renderer.unmount();31const { ReactShallowRenderer } = require('playwright');32const renderer = new ReactShallowRenderer();33const { React } = require('playwright');34const { Component } = React;35renderer.render(<Component />);36renderer.getRenderOutput();37renderer.unmount();38renderer.render(<Component />);39renderer.getRenderOutput();40renderer.unmount();41const { ReactShallowRenderer } = require('playwright');42const renderer = new ReactShallowRenderer();43const { React } = require('playwright');44const { Component } = React;45renderer.render(<Component />);46renderer.getRenderOutput();47renderer.unmount();48renderer.render(<Component />);49renderer.getRenderOutput();50renderer.unmount();51const { ReactShallowRenderer } = require('playwright');52const renderer = new ReactShallowRenderer();53const { React } = require('playwright');54const { Component } = React;55renderer.render(<Component />);56renderer.getRenderOutput();57renderer.unmount();58renderer.render(<Component />);59renderer.getRenderOutput();60renderer.unmount();61const { ReactShallow
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!