Best JavaScript code snippet using playwright-internal
FormControl.test.js
Source:FormControl.test.js
1import * as React from 'react';2import { expect } from 'chai';3import { spy } from 'sinon';4import { getClasses, createMount, describeConformance, act, createClientRender } from 'test/utils';5import Input from '../Input';6import Select from '../Select';7import FormControl from './FormControl';8import useFormControl from './useFormControl';9describe('<FormControl />', () => {10 const mount = createMount();11 const render = createClientRender();12 let classes;13 function TestComponent(props) {14 const context = useFormControl();15 React.useEffect(() => {16 props.contextCallback(context);17 });18 return null;19 }20 before(() => {21 classes = getClasses(<FormControl />);22 });23 describeConformance(<FormControl />, () => ({24 classes,25 inheritComponent: 'div',26 mount,27 refInstanceof: window.HTMLDivElement,28 testComponentPropWith: 'fieldset',29 }));30 describe('initial state', () => {31 it('should have no margin', () => {32 const { container } = render(<FormControl />);33 const root = container.firstChild;34 expect(root).not.to.have.class(classes.marginNormal);35 expect(root).not.to.have.class(classes.marginDense);36 });37 it('can have the margin normal class', () => {38 const { container } = render(<FormControl margin="normal" />);39 const root = container.firstChild;40 expect(root).to.have.class(classes.marginNormal);41 expect(root).not.to.have.class(classes.marginDense);42 });43 it('can have the margin dense class', () => {44 const { container } = render(<FormControl margin="dense" />);45 const root = container.firstChild;46 expect(root).to.have.class(classes.marginDense);47 expect(root).not.to.have.class(classes.marginNormal);48 });49 it('should not be filled initially', () => {50 const readContext = spy();51 render(52 <FormControl>53 <TestComponent contextCallback={readContext} />54 </FormControl>,55 );56 expect(readContext.args[0][0]).to.have.property('filled', false);57 });58 it('should not be focused initially', () => {59 const readContext = spy();60 render(61 <FormControl>62 <TestComponent contextCallback={readContext} />63 </FormControl>,64 );65 expect(readContext.args[0][0]).to.have.property('focused', false);66 });67 });68 describe('prop: required', () => {69 it('should not apply it to the DOM', () => {70 const { container } = render(<FormControl required />);71 expect(container.firstChild).not.to.have.attribute('required');72 });73 });74 describe('prop: disabled', () => {75 it('will be unfocused if it gets disabled', () => {76 const readContext = spy();77 const { container, setProps } = render(78 <FormControl>79 <Input />80 <TestComponent contextCallback={readContext} />81 </FormControl>,82 );83 expect(readContext.args[0][0]).to.have.property('focused', false);84 act(() => {85 container.querySelector('input').focus();86 });87 expect(readContext.args[1][0]).to.have.property('focused', true);88 setProps({ disabled: true });89 expect(readContext.args[2][0]).to.have.property('focused', false);90 });91 });92 describe('prop: focused', () => {93 it('should display input in focused state', () => {94 const readContext = spy();95 const { container } = render(96 <FormControl focused>97 <Input />98 <TestComponent contextCallback={readContext} />99 </FormControl>,100 );101 expect(readContext.args[0][0]).to.have.property('focused', true);102 container.querySelector('input').blur();103 expect(readContext.args[0][0]).to.have.property('focused', true);104 });105 });106 describe('input', () => {107 it('should be filled when a value is set', () => {108 const readContext = spy();109 render(110 <FormControl>111 <Input value="bar" />112 <TestComponent contextCallback={readContext} />113 </FormControl>,114 );115 expect(readContext.args[0][0]).to.have.property('filled', true);116 });117 it('should be filled when a defaultValue is set', () => {118 const readContext = spy();119 render(120 <FormControl>121 <Input defaultValue="bar" />122 <TestComponent contextCallback={readContext} />123 </FormControl>,124 );125 expect(readContext.args[0][0]).to.have.property('filled', true);126 });127 it('should not be adornedStart with an endAdornment', () => {128 const readContext = spy();129 render(130 <FormControl>131 <Input endAdornment={<div />} />132 <TestComponent contextCallback={readContext} />133 </FormControl>,134 );135 expect(readContext.args[0][0]).to.have.property('adornedStart', false);136 });137 it('should be adornedStar with a startAdornment', () => {138 const readContext = spy();139 render(140 <FormControl>141 <Input startAdornment={<div />} />142 <TestComponent contextCallback={readContext} />143 </FormControl>,144 );145 expect(readContext.args[0][0]).to.have.property('adornedStart', true);146 });147 });148 describe('select', () => {149 it('should not be adorned without a startAdornment', () => {150 const readContext = spy();151 render(152 <FormControl>153 <Select value="" />154 <TestComponent contextCallback={readContext} />155 </FormControl>,156 );157 expect(readContext.args[0][0]).to.have.property('adornedStart', false);158 });159 it('should be adorned with a startAdornment', () => {160 const readContext = spy();161 render(162 <FormControl>163 <Select value="" input={<Input startAdornment={<div />} />} />164 <TestComponent contextCallback={readContext} />165 </FormControl>,166 );167 expect(readContext.args[0][0].adornedStart, true);168 });169 });170 describe('useFormControl', () => {171 const FormController = React.forwardRef((_, ref) => {172 const formControl = useFormControl();173 React.useImperativeHandle(ref, () => formControl, [formControl]);174 return null;175 });176 const FormControlled = React.forwardRef(function FormControlled(props, ref) {177 return (178 <FormControl {...props}>179 <FormController ref={ref} />180 </FormControl>181 );182 });183 describe('from props', () => {184 it('should have the required prop from the instance', () => {185 const formControlRef = React.createRef();186 const { setProps } = render(<FormControlled ref={formControlRef} />);187 expect(formControlRef.current).to.have.property('required', false);188 setProps({ required: true });189 expect(formControlRef.current).to.have.property('required', true);190 });191 it('should have the error prop from the instance', () => {192 const formControlRef = React.createRef();193 const { setProps } = render(<FormControlled ref={formControlRef} />);194 expect(formControlRef.current).to.have.property('error', false);195 setProps({ error: true });196 expect(formControlRef.current).to.have.property('error', true);197 });198 it('should have the margin prop from the instance', () => {199 const formControlRef = React.createRef();200 const { setProps } = render(<FormControlled ref={formControlRef} />);201 expect(formControlRef.current).to.have.property('margin', 'none');202 setProps({ margin: 'dense' });203 expect(formControlRef.current).to.have.property('margin', 'dense');204 });205 it('should have the fullWidth prop from the instance', () => {206 const formControlRef = React.createRef();207 const { setProps } = render(<FormControlled ref={formControlRef} />);208 expect(formControlRef.current).to.have.property('fullWidth', false);209 setProps({ fullWidth: true });210 expect(formControlRef.current).to.have.property('fullWidth', true);211 });212 });213 describe('callbacks', () => {214 describe('onFilled', () => {215 it('should set the filled state', () => {216 const formControlRef = React.createRef();217 render(<FormControlled ref={formControlRef} />);218 expect(formControlRef.current).to.have.property('filled', false);219 act(() => {220 formControlRef.current.onFilled();221 });222 expect(formControlRef.current).to.have.property('filled', true);223 act(() => {224 formControlRef.current.onFilled();225 });226 expect(formControlRef.current).to.have.property('filled', true);227 });228 });229 describe('onEmpty', () => {230 it('should clean the filled state', () => {231 const formControlRef = React.createRef();232 render(<FormControlled ref={formControlRef} />);233 act(() => {234 formControlRef.current.onFilled();235 });236 expect(formControlRef.current).to.have.property('filled', true);237 act(() => {238 formControlRef.current.onEmpty();239 });240 expect(formControlRef.current).to.have.property('filled', false);241 act(() => {242 formControlRef.current.onEmpty();243 });244 expect(formControlRef.current).to.have.property('filled', false);245 });246 });247 describe('handleFocus', () => {248 it('should set the focused state', () => {249 const formControlRef = React.createRef();250 render(<FormControlled ref={formControlRef} />);251 expect(formControlRef.current).to.have.property('focused', false);252 act(() => {253 formControlRef.current.onFocus();254 });255 expect(formControlRef.current).to.have.property('focused', true);256 act(() => {257 formControlRef.current.onFocus();258 });259 expect(formControlRef.current).to.have.property('focused', true);260 });261 });262 describe('handleBlur', () => {263 it('should clear the focused state', () => {264 const formControlRef = React.createRef();265 render(<FormControlled ref={formControlRef} />);266 expect(formControlRef.current).to.have.property('focused', false);267 act(() => {268 formControlRef.current.onFocus();269 });270 expect(formControlRef.current).to.have.property('focused', true);271 act(() => {272 formControlRef.current.onBlur();273 });274 expect(formControlRef.current).to.have.property('focused', false);275 act(() => {276 formControlRef.current.onBlur();277 });278 expect(formControlRef.current).to.have.property('focused', false);279 });280 });281 });282 });...
readContext.js
Source:readContext.js
...14 but for now, Relay needs the dispatcher to read context. */15React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,16 ReactCurrentDispatcher = _React$__SECRET_INTER.ReactCurrentDispatcher,17 ReactCurrentOwner = _React$__SECRET_INTER.ReactCurrentOwner;18function readContext(Context) {19 var dispatcher = ReactCurrentDispatcher != null ? ReactCurrentDispatcher.current : ReactCurrentOwner.currentDispatcher;20 return dispatcher.readContext(Context);21}...
ReactFiberDispatcher.js
Source:ReactFiberDispatcher.js
1/**2 * Copyright (c) Facebook, Inc. and its affiliates.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 */9import {readContext} from './ReactFiberNewContext';10import {11 useCallback,12 useContext,13 useEffect,14 useImperativeMethods,15 useLayoutEffect,16 useMemo,17 useReducer,18 useRef,19 useState,20} from './ReactFiberHooks';21export const Dispatcher = {22 readContext,23 useCallback,24 useContext,25 useEffect,26 useImperativeMethods,27 useLayoutEffect,28 useMemo,29 useReducer,30 useRef,31 useState,32};33export const DispatcherWithoutHooks = {34 readContext,...
Using AI Code Generation
1const { readContext } = require('playwright/lib/server/chromium/crBrowser');2const context = await readContext(page);3const cookies = await context.cookies();4console.log(cookies);5const { readContext } = require('playwright/lib/server/chromium/crBrowser');6const context = await readContext(page);7const cookies = await context.cookies();8console.log(cookies);9const { readContext } = require('playwright/lib/server/chromium/crBrowser');10const context = await readContext(page);11const cookies = await context.cookies();12console.log(cookies);13const { readContext } = require('playwright/lib/server/chromium/crBrowser');14const context = await readContext(page);15const cookies = await context.cookies();16console.log(cookies);17const { readContext } = require('playwright/lib/server/chromium/crBrowser');18const context = await readContext(page);19const cookies = await context.cookies();20console.log(cookies);21const { readContext } = require('playwright/lib/server/chromium/crBrowser');22const context = await readContext(page);23const cookies = await context.cookies();24console.log(cookies);25const { readContext } = require('playwright/lib/server/chromium/crBrowser');26const context = await readContext(page);27const cookies = await context.cookies();28console.log(cookies);29const { readContext } = require('playwright/lib/server/chromium/crBrowser');30const context = await readContext(page);31const cookies = await context.cookies();32console.log(cookies);33const { readContext } = require('playwright/lib/server/chromium/crBrowser');34const context = await readContext(page);35const cookies = await context.cookies();36console.log(cookies);37const { readContext } = require('playwright/lib/server/chromium/crBrowser');38const context = await readContext(page);39const cookies = await context.cookies();40console.log(cookies);
Using AI Code Generation
1const { readContext } = require('playwright/lib/server/chromium/crBrowser');2const context = readContext(page);3const { cookies } = await context.cookies();4console.log(cookies);5const { readContext } = require('playwright/lib/server/chromium/crBrowser');6const context = readContext(page);7const { cookies } = await context.cookies();8console.log(cookies);9const { readContext } = require('playwright/lib/server/chromium/crBrowser');10const context = readContext(page);11const { cookies } = await context.cookies();12console.log(cookies);13const { readContext } = require('playwright/lib/server/chromium/crBrowser');14const context = readContext(page);15const { cookies } = await context.cookies();16console.log(cookies);17const { readContext } = require('playwright/lib/server/chromium/crBrowser');18const context = readContext(page);19const { cookies } = await context.cookies();20console.log(cookies);21const { readContext } = require('playwright/lib/server/chromium/crBrowser');22const context = readContext(page);23const { cookies } = await context.cookies();24console.log(cookies);25const { readContext } = require('playwright/lib/server/chromium/crBrowser');26const context = readContext(page);27const { cookies } = await context.cookies();28console.log(cookies);29const { readContext } = require('playwright/lib/server/chromium/crBrowser');30const context = readContext(page);31const { cookies } = await context.cookies();32console.log(cookies);33const { readContext } = require('playwright/lib/server/chromium/crBrowser');34const context = readContext(page);35const { cookies } = await context.cookies();36console.log(cookies);37const { readContext } = require('playwright/lib/server/chromium/crBrowser');38const context = readContext(page);39const { cookies }
Using AI Code Generation
1const { readContext } = require('playwright');2const context = await readContext(browserContext);3const context = await page.context();4const { readContext } = require('playwright');5const context = await readContext(browserContext);6const context = await page.context();7const { readContext } = require('playwright');8const context = await readContext(browserContext);9const context = await page.context();10const { readContext } = require('playwright');11const context = await readContext(browserContext);
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!!