How to use createRoot method in Testcafe

Best JavaScript code snippet using testcafe

codegen.spec.js

Source:codegen.spec.js Github

copy

Full Screen

...14var src_1 = require("../src");15var runtimeHelpers_1 = require("../src/runtimeHelpers");16var testUtils_1 = require("./testUtils");17var shared_1 = require("@vue/shared");18function createRoot(options) {19 if (options === void 0) { options = {}; }20 return __assign({ type: 0, children: [], helpers: [], components: [], directives: [], hoists: [], cached: 0, codegenNode: src_1.createSimpleExpression("null", false), loc: src_1.locStub }, options);21}22describe('compiler: codegen', function () {23 test('module mode preamble', function () {24 var root = createRoot({25 helpers: [runtimeHelpers_1.CREATE_VNODE, runtimeHelpers_1.RESOLVE_DIRECTIVE]26 });27 var code = src_1.generate(root, { mode: 'module' }).code;28 expect(code).toMatch("import { " + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.CREATE_VNODE] + ", " + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.RESOLVE_DIRECTIVE] + " } from \"vue\"");29 expect(code).toMatchSnapshot();30 });31 test('function mode preamble', function () {32 var root = createRoot({33 helpers: [runtimeHelpers_1.CREATE_VNODE, runtimeHelpers_1.RESOLVE_DIRECTIVE]34 });35 var code = src_1.generate(root, { mode: 'function' }).code;36 expect(code).toMatch("const _Vue = Vue");37 expect(code).toMatch("const { " + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.CREATE_VNODE] + ": _" + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.CREATE_VNODE] + ", " + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.RESOLVE_DIRECTIVE] + ": _" + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.RESOLVE_DIRECTIVE] + " } = _Vue");38 expect(code).toMatchSnapshot();39 });40 test('function mode preamble w/ prefixIdentifiers: true', function () {41 var root = createRoot({42 helpers: [runtimeHelpers_1.CREATE_VNODE, runtimeHelpers_1.RESOLVE_DIRECTIVE]43 });44 var code = src_1.generate(root, {45 mode: 'function',46 prefixIdentifiers: true47 }).code;48 expect(code).not.toMatch("const _Vue = Vue");49 expect(code).toMatch("const { " + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.CREATE_VNODE] + ", " + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.RESOLVE_DIRECTIVE] + " } = Vue");50 expect(code).toMatchSnapshot();51 });52 test('assets', function () {53 var root = createRoot({54 components: ["Foo", "bar-baz", "barbaz"],55 directives: ["my_dir"]56 });57 var code = src_1.generate(root, { mode: 'function' }).code;58 expect(code).toMatch("const _component_Foo = _" + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.RESOLVE_COMPONENT] + "(\"Foo\")\n");59 expect(code).toMatch("const _component_bar_baz = _" + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.RESOLVE_COMPONENT] + "(\"bar-baz\")\n");60 expect(code).toMatch("const _component_barbaz = _" + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.RESOLVE_COMPONENT] + "(\"barbaz\")\n");61 expect(code).toMatch("const _directive_my_dir = _" + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.RESOLVE_DIRECTIVE] + "(\"my_dir\")\n");62 expect(code).toMatchSnapshot();63 });64 test('hoists', function () {65 var root = createRoot({66 hoists: [67 src_1.createSimpleExpression("hello", false, src_1.locStub),68 src_1.createObjectExpression([69 src_1.createObjectProperty(src_1.createSimpleExpression("id", true, src_1.locStub), src_1.createSimpleExpression("foo", true, src_1.locStub))70 ], src_1.locStub)71 ]72 });73 var code = src_1.generate(root).code;74 expect(code).toMatch("const _hoisted_1 = hello");75 expect(code).toMatch("const _hoisted_2 = { id: \"foo\" }");76 expect(code).toMatchSnapshot();77 });78 test('prefixIdentifiers: true should inject _ctx statement', function () {79 var code = src_1.generate(createRoot(), { prefixIdentifiers: true }).code;80 expect(code).toMatch("const _ctx = this\n");81 expect(code).toMatchSnapshot();82 });83 test('static text', function () {84 var code = src_1.generate(createRoot({85 codegenNode: {86 type: 2,87 content: 'hello',88 loc: src_1.locStub89 }90 })).code;91 expect(code).toMatch("return \"hello\"");92 expect(code).toMatchSnapshot();93 });94 test('interpolation', function () {95 var code = src_1.generate(createRoot({96 codegenNode: src_1.createInterpolation("hello", src_1.locStub)97 })).code;98 expect(code).toMatch("return _" + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.TO_STRING] + "(hello)");99 expect(code).toMatchSnapshot();100 });101 test('comment', function () {102 var code = src_1.generate(createRoot({103 codegenNode: {104 type: 3,105 content: 'foo',106 loc: src_1.locStub107 }108 })).code;109 expect(code).toMatch("return _" + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.CREATE_COMMENT] + "(\"foo\")");110 expect(code).toMatchSnapshot();111 });112 test('compound expression', function () {113 var code = src_1.generate(createRoot({114 codegenNode: src_1.createCompoundExpression([115 "_ctx.",116 src_1.createSimpleExpression("foo", false, src_1.locStub),117 " + ",118 {119 type: 5,120 loc: src_1.locStub,121 content: src_1.createSimpleExpression("bar", false, src_1.locStub)122 }123 ])124 })).code;125 expect(code).toMatch("return _ctx.foo + _" + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.TO_STRING] + "(bar)");126 expect(code).toMatchSnapshot();127 });128 test('ifNode', function () {129 var code = src_1.generate(createRoot({130 codegenNode: {131 type: 9,132 loc: src_1.locStub,133 branches: [],134 codegenNode: src_1.createSequenceExpression([135 src_1.createSimpleExpression('foo', false),136 src_1.createSimpleExpression('bar', false)137 ])138 }139 })).code;140 expect(code).toMatch("return (foo, bar)");141 expect(code).toMatchSnapshot();142 });143 test('forNode', function () {144 var code = src_1.generate(createRoot({145 codegenNode: {146 type: 11,147 loc: src_1.locStub,148 source: src_1.createSimpleExpression('foo', false),149 valueAlias: undefined,150 keyAlias: undefined,151 objectIndexAlias: undefined,152 children: [],153 codegenNode: src_1.createSequenceExpression([154 src_1.createSimpleExpression('foo', false),155 src_1.createSimpleExpression('bar', false)156 ])157 }158 })).code;159 expect(code).toMatch("return (foo, bar)");160 expect(code).toMatchSnapshot();161 });162 test('Element (callExpression + objectExpression + TemplateChildNode[])', function () {163 var code = src_1.generate(createRoot({164 codegenNode: testUtils_1.createElementWithCodegen([165 "\"div\"",166 src_1.createObjectExpression([167 src_1.createObjectProperty(src_1.createSimpleExpression("id", true, src_1.locStub), src_1.createSimpleExpression("foo", true, src_1.locStub)),168 src_1.createObjectProperty(src_1.createSimpleExpression("prop", false, src_1.locStub), src_1.createSimpleExpression("bar", false, src_1.locStub)),169 src_1.createObjectProperty({170 type: 8,171 loc: src_1.locStub,172 children: [173 "foo + ",174 src_1.createSimpleExpression("bar", false, src_1.locStub)175 ]176 }, src_1.createSimpleExpression("bar", false, src_1.locStub))177 ], src_1.locStub),178 [179 testUtils_1.createElementWithCodegen([180 "\"p\"",181 src_1.createObjectExpression([182 src_1.createObjectProperty(src_1.createSimpleExpression("some-key", true, src_1.locStub), src_1.createSimpleExpression("foo", true, src_1.locStub))183 ], src_1.locStub)184 ])185 ],186 shared_1.PatchFlags.FULL_PROPS + ''187 ])188 })).code;189 expect(code).toMatch("\n return _" + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.CREATE_VNODE] + "(\"div\", {\n id: \"foo\",\n [prop]: bar,\n [foo + bar]: bar\n }, [\n _" + runtimeHelpers_1.helperNameMap[runtimeHelpers_1.CREATE_VNODE] + "(\"p\", { \"some-key\": \"foo\" })\n ], " + shared_1.PatchFlags.FULL_PROPS + ")");190 expect(code).toMatchSnapshot();191 });192 test('ArrayExpression', function () {193 var code = src_1.generate(createRoot({194 codegenNode: src_1.createArrayExpression([195 src_1.createSimpleExpression("foo", false),196 src_1.createCallExpression("bar", ["baz"])197 ])198 })).code;199 expect(code).toMatch("return [\n foo,\n bar(baz)\n ]");200 expect(code).toMatchSnapshot();201 });202 test('SequenceExpression', function () {203 var code = src_1.generate(createRoot({204 codegenNode: src_1.createSequenceExpression([205 src_1.createSimpleExpression("foo", false),206 src_1.createCallExpression("bar", ["baz"])207 ])208 })).code;209 expect(code).toMatch("return (foo, bar(baz))");210 expect(code).toMatchSnapshot();211 });212 test('ConditionalExpression', function () {213 var code = src_1.generate(createRoot({214 codegenNode: src_1.createConditionalExpression(src_1.createSimpleExpression("ok", false), src_1.createCallExpression("foo"), src_1.createConditionalExpression(src_1.createSimpleExpression("orNot", false), src_1.createCallExpression("bar"), src_1.createCallExpression("baz")))215 })).code;216 expect(code).toMatch("return ok\n ? foo()\n : orNot\n ? bar()\n : baz()");217 expect(code).toMatchSnapshot();218 });219 test('CacheExpression', function () {220 var code = src_1.generate(createRoot({221 cached: 1,222 codegenNode: src_1.createCacheExpression(1, src_1.createSimpleExpression("foo", false))223 }), {224 mode: 'module',225 prefixIdentifiers: true226 }).code;227 expect(code).toMatch("const _cache = _ctx.$cache");228 expect(code).toMatch("_cache[1] || (_cache[1] = foo)");229 expect(code).toMatchSnapshot();230 });231 test('CacheExpression w/ isVNode: true', function () {232 var code = src_1.generate(createRoot({233 cached: 1,234 codegenNode: src_1.createCacheExpression(1, src_1.createSimpleExpression("foo", false), true)235 }), {236 mode: 'module',237 prefixIdentifiers: true238 }).code;239 expect(code).toMatch("const _cache = _ctx.$cache");240 expect(code).toMatch("\n _cache[1] || (\n setBlockTracking(-1),\n _cache[1] = foo,\n setBlockTracking(1),\n _cache[1]\n )\n ".trim());241 expect(code).toMatchSnapshot();242 });...

Full Screen

Full Screen

ReactDOMRoot-test.js

Source:ReactDOMRoot-test.js Github

copy

Full Screen

...27 });28 return;29 }30 it('renders children', () => {31 const root = ReactDOM.createRoot(container);32 root.render(<div>Hi</div>);33 Scheduler.unstable_flushAll();34 expect(container.textContent).toEqual('Hi');35 });36 it('warns if a callback parameter is provided to render', () => {37 const callback = jest.fn();38 const root = ReactDOM.createRoot(container);39 expect(() =>40 root.render(<div>Hi</div>, callback),41 ).toErrorDev(42 'render(...): does not support the second callback argument. ' +43 'To execute a side effect after rendering, declare it in a component body with useEffect().',44 {withoutStack: true},45 );46 Scheduler.unstable_flushAll();47 expect(callback).not.toHaveBeenCalled();48 });49 it('warns if a callback parameter is provided to unmount', () => {50 const callback = jest.fn();51 const root = ReactDOM.createRoot(container);52 root.render(<div>Hi</div>);53 expect(() =>54 root.unmount(callback),55 ).toErrorDev(56 'unmount(...): does not support a callback argument. ' +57 'To execute a side effect after rendering, declare it in a component body with useEffect().',58 {withoutStack: true},59 );60 Scheduler.unstable_flushAll();61 expect(callback).not.toHaveBeenCalled();62 });63 it('unmounts children', () => {64 const root = ReactDOM.createRoot(container);65 root.render(<div>Hi</div>);66 Scheduler.unstable_flushAll();67 expect(container.textContent).toEqual('Hi');68 root.unmount();69 Scheduler.unstable_flushAll();70 expect(container.textContent).toEqual('');71 });72 it('supports hydration', async () => {73 const markup = await new Promise(resolve =>74 resolve(75 ReactDOMServer.renderToString(76 <div>77 <span className="extra" />78 </div>,79 ),80 ),81 );82 // Does not hydrate by default83 const container1 = document.createElement('div');84 container1.innerHTML = markup;85 const root1 = ReactDOM.createRoot(container1);86 root1.render(87 <div>88 <span />89 </div>,90 );91 Scheduler.unstable_flushAll();92 // Accepts `hydrate` option93 const container2 = document.createElement('div');94 container2.innerHTML = markup;95 const root2 = ReactDOM.createRoot(container2, {hydrate: true});96 root2.render(97 <div>98 <span />99 </div>,100 );101 expect(() => Scheduler.unstable_flushAll()).toErrorDev('Extra attributes');102 });103 it('does not clear existing children', async () => {104 container.innerHTML = '<div>a</div><div>b</div>';105 const root = ReactDOM.createRoot(container);106 root.render(107 <div>108 <span>c</span>109 <span>d</span>110 </div>,111 );112 Scheduler.unstable_flushAll();113 expect(container.textContent).toEqual('abcd');114 root.render(115 <div>116 <span>d</span>117 <span>c</span>118 </div>,119 );120 Scheduler.unstable_flushAll();121 expect(container.textContent).toEqual('abdc');122 });123 it('throws a good message on invalid containers', () => {124 expect(() => {125 ReactDOM.createRoot(<div>Hi</div>);126 }).toThrow('createRoot(...): Target container is not a DOM element.');127 });128 it('warns when rendering with legacy API into createRoot() container', () => {129 const root = ReactDOM.createRoot(container);130 root.render(<div>Hi</div>);131 Scheduler.unstable_flushAll();132 expect(container.textContent).toEqual('Hi');133 expect(() => {134 ReactDOM.render(<div>Bye</div>, container);135 }).toErrorDev(136 [137 // We care about this warning:138 'You are calling ReactDOM.render() on a container that was previously ' +139 'passed to ReactDOM.createRoot(). This is not supported. ' +140 'Did you mean to call root.render(element)?',141 // This is more of a symptom but restructuring the code to avoid it isn't worth it:142 'Replacing React-rendered children with a new root component.',143 ],144 {withoutStack: true},145 );146 Scheduler.unstable_flushAll();147 // This works now but we could disallow it:148 expect(container.textContent).toEqual('Bye');149 });150 it('warns when hydrating with legacy API into createRoot() container', () => {151 const root = ReactDOM.createRoot(container);152 root.render(<div>Hi</div>);153 Scheduler.unstable_flushAll();154 expect(container.textContent).toEqual('Hi');155 expect(() => {156 ReactDOM.hydrate(<div>Hi</div>, container);157 }).toErrorDev(158 [159 // We care about this warning:160 'You are calling ReactDOM.hydrate() on a container that was previously ' +161 'passed to ReactDOM.createRoot(). This is not supported. ' +162 'Did you mean to call createRoot(container, {hydrate: true}).render(element)?',163 // This is more of a symptom but restructuring the code to avoid it isn't worth it:164 'Replacing React-rendered children with a new root component.',165 ],166 {withoutStack: true},167 );168 });169 it('warns when unmounting with legacy API (no previous content)', () => {170 const root = ReactDOM.createRoot(container);171 root.render(<div>Hi</div>);172 Scheduler.unstable_flushAll();173 expect(container.textContent).toEqual('Hi');174 let unmounted = false;175 expect(() => {176 unmounted = ReactDOM.unmountComponentAtNode(container);177 }).toErrorDev(178 [179 // We care about this warning:180 'You are calling ReactDOM.unmountComponentAtNode() on a container that was previously ' +181 'passed to ReactDOM.createRoot(). This is not supported. Did you mean to call root.unmount()?',182 // This is more of a symptom but restructuring the code to avoid it isn't worth it:183 "The node you're attempting to unmount was rendered by React and is not a top-level container.",184 ],185 {withoutStack: true},186 );187 expect(unmounted).toBe(false);188 Scheduler.unstable_flushAll();189 expect(container.textContent).toEqual('Hi');190 root.unmount();191 Scheduler.unstable_flushAll();192 expect(container.textContent).toEqual('');193 });194 it('warns when unmounting with legacy API (has previous content)', () => {195 // Currently createRoot().render() doesn't clear this.196 container.appendChild(document.createElement('div'));197 // The rest is the same as test above.198 const root = ReactDOM.createRoot(container);199 root.render(<div>Hi</div>);200 Scheduler.unstable_flushAll();201 expect(container.textContent).toEqual('Hi');202 let unmounted = false;203 expect(() => {204 unmounted = ReactDOM.unmountComponentAtNode(container);205 }).toErrorDev('Did you mean to call root.unmount()?', {withoutStack: true});206 expect(unmounted).toBe(false);207 Scheduler.unstable_flushAll();208 expect(container.textContent).toEqual('Hi');209 root.unmount();210 Scheduler.unstable_flushAll();211 expect(container.textContent).toEqual('');212 });213 it('warns when passing legacy container to createRoot()', () => {214 ReactDOM.render(<div>Hi</div>, container);215 expect(() => {216 ReactDOM.createRoot(container);217 }).toErrorDev(218 'You are calling ReactDOM.createRoot() on a container that was previously ' +219 'passed to ReactDOM.render(). This is not supported.',220 {withoutStack: true},221 );222 });223 it('warns when creating two roots managing the same container', () => {224 ReactDOM.createRoot(container);225 expect(() => {226 ReactDOM.createRoot(container);227 }).toErrorDev(228 'You are calling ReactDOM.createRoot() on a container that ' +229 'has already been passed to createRoot() before. Instead, call ' +230 'root.render() on the existing root instead if you want to update it.',231 {withoutStack: true},232 );233 });234 it('does not warn when creating second root after first one is unmounted', () => {235 const root = ReactDOM.createRoot(container);236 root.unmount();237 Scheduler.unstable_flushAll();238 ReactDOM.createRoot(container); // No warning239 });240 it('warns if creating a root on the document.body', async () => {241 expect(() => {242 ReactDOM.createRoot(document.body);243 }).toErrorDev(244 'createRoot(): Creating roots directly with document.body is ' +245 'discouraged, since its children are often manipulated by third-party ' +246 'scripts and browser extensions. This may lead to subtle ' +247 'reconciliation issues. Try using a container element created ' +248 'for your app.',249 {withoutStack: true},250 );251 });252 it('warns if updating a root that has had its contents removed', async () => {253 const root = ReactDOM.createRoot(container);254 root.render(<div>Hi</div>);255 Scheduler.unstable_flushAll();256 container.innerHTML = '';257 expect(() => {258 root.render(<div>Hi</div>);259 }).toErrorDev(260 'render(...): It looks like the React-rendered content of the ' +261 'root container was removed without using React. This is not ' +262 'supported and will cause errors. Instead, call ' +263 "root.unmount() to empty a root's container.",264 {withoutStack: true},265 );266 });267});

Full Screen

Full Screen

ReactDOMRoot-test.internal.js

Source:ReactDOMRoot-test.internal.js Github

copy

Full Screen

...64 ReactDOMServer = require('react-dom/server');65 AsyncMode = React.unstable_AsyncMode;66 });67 it('renders children', () => {68 const root = ReactDOM.createRoot(container);69 root.render(<div>Hi</div>);70 flush();71 expect(container.textContent).toEqual('Hi');72 });73 it('unmounts children', () => {74 const root = ReactDOM.createRoot(container);75 root.render(<div>Hi</div>);76 flush();77 expect(container.textContent).toEqual('Hi');78 root.unmount();79 flush();80 expect(container.textContent).toEqual('');81 });82 it('`root.render` returns a thenable work object', () => {83 const root = ReactDOM.createRoot(container);84 const work = root.render(<AsyncMode>Hi</AsyncMode>);85 let ops = [];86 work.then(() => {87 ops.push('inside callback: ' + container.textContent);88 });89 ops.push('before committing: ' + container.textContent);90 flush();91 ops.push('after committing: ' + container.textContent);92 expect(ops).toEqual([93 'before committing: ',94 // `then` callback should fire during commit phase95 'inside callback: Hi',96 'after committing: Hi',97 ]);98 });99 it('resolves `work.then` callback synchronously if the work already committed', () => {100 const root = ReactDOM.createRoot(container);101 const work = root.render(<AsyncMode>Hi</AsyncMode>);102 flush();103 let ops = [];104 work.then(() => {105 ops.push('inside callback');106 });107 expect(ops).toEqual(['inside callback']);108 });109 it('supports hydration', async () => {110 const markup = await new Promise(resolve =>111 resolve(112 ReactDOMServer.renderToString(113 <div>114 <span className="extra" />115 </div>,116 ),117 ),118 );119 // Does not hydrate by default120 const container1 = document.createElement('div');121 container1.innerHTML = markup;122 const root1 = ReactDOM.createRoot(container1);123 root1.render(124 <div>125 <span />126 </div>,127 );128 flush();129 // Accepts `hydrate` option130 const container2 = document.createElement('div');131 container2.innerHTML = markup;132 const root2 = ReactDOM.createRoot(container2, {hydrate: true});133 root2.render(134 <div>135 <span />136 </div>,137 );138 expect(flush).toWarnDev('Extra attributes');139 });140 it('does not clear existing children', async () => {141 container.innerHTML = '<div>a</div><div>b</div>';142 const root = ReactDOM.createRoot(container);143 root.render(144 <div>145 <span>c</span>146 <span>d</span>147 </div>,148 );149 flush();150 expect(container.textContent).toEqual('abcd');151 root.render(152 <div>153 <span>d</span>154 <span>c</span>155 </div>,156 );157 flush();158 expect(container.textContent).toEqual('abdc');159 });160 it('can defer a commit by batching it', () => {161 const root = ReactDOM.createRoot(container);162 const batch = root.createBatch();163 batch.render(<div>Hi</div>);164 // Hasn't committed yet165 expect(container.textContent).toEqual('');166 // Commit167 batch.commit();168 expect(container.textContent).toEqual('Hi');169 });170 it('does not restart a completed batch when committing if there were no intervening updates', () => {171 let ops = [];172 function Foo(props) {173 ops.push('Foo');174 return props.children;175 }176 const root = ReactDOM.createRoot(container);177 const batch = root.createBatch();178 batch.render(<Foo>Hi</Foo>);179 // Flush all async work.180 flush();181 // Root should complete without committing.182 expect(ops).toEqual(['Foo']);183 expect(container.textContent).toEqual('');184 ops = [];185 // Commit. Shouldn't re-render Foo.186 batch.commit();187 expect(ops).toEqual([]);188 expect(container.textContent).toEqual('Hi');189 });190 it('can wait for a batch to finish', () => {191 const root = ReactDOM.createRoot(container);192 const batch = root.createBatch();193 batch.render(<AsyncMode>Foo</AsyncMode>);194 flush();195 // Hasn't updated yet196 expect(container.textContent).toEqual('');197 let ops = [];198 batch.then(() => {199 // Still hasn't updated200 ops.push(container.textContent);201 // Should synchronously commit202 batch.commit();203 ops.push(container.textContent);204 });205 expect(ops).toEqual(['', 'Foo']);206 });207 it('`batch.render` returns a thenable work object', () => {208 const root = ReactDOM.createRoot(container);209 const batch = root.createBatch();210 const work = batch.render('Hi');211 let ops = [];212 work.then(() => {213 ops.push('inside callback: ' + container.textContent);214 });215 ops.push('before committing: ' + container.textContent);216 batch.commit();217 ops.push('after committing: ' + container.textContent);218 expect(ops).toEqual([219 'before committing: ',220 // `then` callback should fire during commit phase221 'inside callback: Hi',222 'after committing: Hi',223 ]);224 });225 it('can commit an empty batch', () => {226 const root = ReactDOM.createRoot(container);227 root.render(<AsyncMode>1</AsyncMode>);228 expire(2000);229 // This batch has a later expiration time than the earlier update.230 const batch = root.createBatch();231 // This should not flush the earlier update.232 batch.commit();233 expect(container.textContent).toEqual('');234 flush();235 expect(container.textContent).toEqual('1');236 });237 it('two batches created simultaneously are committed separately', () => {238 // (In other words, they have distinct expiration times)239 const root = ReactDOM.createRoot(container);240 const batch1 = root.createBatch();241 batch1.render(1);242 const batch2 = root.createBatch();243 batch2.render(2);244 expect(container.textContent).toEqual('');245 batch1.commit();246 expect(container.textContent).toEqual('1');247 batch2.commit();248 expect(container.textContent).toEqual('2');249 });250 it('commits an earlier batch without committing a later batch', () => {251 const root = ReactDOM.createRoot(container);252 const batch1 = root.createBatch();253 batch1.render(1);254 // This batch has a later expiration time255 expire(2000);256 const batch2 = root.createBatch();257 batch2.render(2);258 expect(container.textContent).toEqual('');259 batch1.commit();260 expect(container.textContent).toEqual('1');261 batch2.commit();262 expect(container.textContent).toEqual('2');263 });264 it('commits a later batch without committing an earlier batch', () => {265 const root = ReactDOM.createRoot(container);266 const batch1 = root.createBatch();267 batch1.render(1);268 // This batch has a later expiration time269 expire(2000);270 const batch2 = root.createBatch();271 batch2.render(2);272 expect(container.textContent).toEqual('');273 batch2.commit();274 expect(container.textContent).toEqual('2');275 batch1.commit();276 flush();277 expect(container.textContent).toEqual('1');278 });279});

Full Screen

Full Screen

client.js

Source:client.js Github

copy

Full Screen

...16 400,17 Surface.SurfaceShape.Cylinder18 );19 introRoot = r360.renderToSurface(20 r360.createRoot('TourismAppVR', {}),21 introPanel22 );23 marketPanel = new Surface(24 100,25 100,26 Surface.SurfaceShape.Flat27 )28 marketPanel.setAngle(29 0.2,30 031 );32 museumPanel = new Surface(33 100,34 100,35 Surface.SurfaceShape.Flat36 )37 museumPanel.setAngle(38 Math.PI / 2,39 040 );41 restaurantPanel = new Surface(42 100,43 100,44 Surface.SurfaceShape.Flat45 )46 restaurantPanel.setAngle(47 -Math.PI / 2,48 049 );50 shoppingPanel = new Surface(51 100,52 100,53 Surface.SurfaceShape.Flat54 );55 /* r360.renderToSurface(56 r360.createRoot('InfoPanel',{}),57 marketPanel58 );59 r360.renderToSurface(60 r360.createRoot('InfoPanel',{}),61 shoppingPanel62 );63 r360.renderToSurface(64 r360.createRoot('InfoPanel',{}),65 museumPanel66 );67 r360.renderToSurface(68 r360.createRoot('InfoPanel',{}),69 restaurantPanel70 ); */71 shoppingPanel.setAngle(72 3.6,73 074 );75 r360.compositor.setBackground(r360.getAssetURL('gdansk.jpg'));76}77class surfaceModule extends Module{78 constructor(){79 super('surfaceModule');80 }81 resizeSurface(width, height, id){82 if(id === 'museum'){83 museumPanel.resize(width, height);84 } else if (id === 'restaurant'){85 restaurantPanel.resize(width, height);86 } else if (id === 'shopping'){87 shoppingPanel.resize(width, height);88 } else if (id === 'market'){89 marketPanel.resize(width, height);90 }91 }92 start(){93 r360.renderToSurface(94 r360.createRoot('InfoPanel',{id:'market', text: 'Browse our incredible market' }),95 marketPanel96 );97 98 r360.renderToSurface(99 r360.createRoot('InfoPanel',{id:'shopping', text: 'Shop until you drop!'}),100 shoppingPanel101 );102 103 r360.renderToSurface(104 r360.createRoot('InfoPanel',{id:'museum', text: 'The Life of Pablo Piccasso: Blue.'}),105 museumPanel106 );107 108 r360.renderToSurface(109 r360.createRoot('InfoPanel',{id:'restaurant', text: 'Enjoy a delecious beer at our restaurants. '}),110 restaurantPanel111 );112 r360.detachRoot(introRoot);113 }114}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5});6const createTestCafe = require('testcafe');7let testcafe = null;8createTestCafe('localhost', 1337, 1338)9 .then(tc => {10 testcafe = tc;11 const runner = testcafe.createRunner();12 .src('test.js')13 .browsers('chrome')14 .run();15 })16 .then(failedCount => {17 console.log('Tests failed: ' + failedCount);18 testcafe.close();19 });20* Microsoft Edge (legacy and Chromium-based)21We welcome contributions from the community. For more information on how to contribute, see [CONTRIBUTING.md](

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5 const articleHeader = await Selector('.result-content').find('h1');6 let headerText = await articleHeader.innerText;7});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#tried-test-cafe')5 .click('#submit-button');6 const articleHeader = await Selector('.result-content').find('h1');7 let headerText = await articleHeader.innerText;8});9import { Selector } from 'testcafe';10test('My first test', async t => {11 .typeText('#developer-name', 'John Smith')12 .click('#tried-test-cafe')13 .click('#submit-button');14 const articleHeader = await Selector('.result-content').find('h1');15 let headerText = await articleHeader.innerText;16});17import { Selector } from 'testcafe';18test('My first test', async t => {19 .typeText('#developer-name', 'John Smith')20 .click('#tried-test-cafe')21 .click('#submit-button');22 const articleHeader = await Selector('.result-content').find('h1');23 let headerText = await articleHeader.innerText;24});25import { Selector } from 'testcafe';26test('My first test', async t => {27 .typeText('#developer-name', 'John Smith')28 .click('#tried-test-cafe')29 .click('#submit-button');30 const articleHeader = await Selector('.result-content').find('h1');31 let headerText = await articleHeader.innerText;32});33import { Selector } from 'testcafe';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector, t } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#tried-test-cafe')5 .click('#submit-button');6});7const createRoot = async () => {8 const root = await Selector('#root');9 return root;10};11test('My second test', async t => {12 const root = await createRoot();13 .expect(root.innerText).eql('Hello World!');14});15import { Selector, t } from 'testcafe';16class Page {17 constructor () {18 this.nameInput = Selector('#developer-name');19 this.triedTestCafeCheckbox = Selector('#tried-test-cafe');20 this.submitButton = Selector('#submit-button');21 }22}23const page = new Page();24test('My first test', async t => {25 .typeText(page.nameInput, 'John Smith')26 .click(page.triedTestCafeCheckbox)27 .click(page.submitButton);28});29const createRoot = async () => {30 const root = await Selector('#root');31 return root;32};33test('My second test', async t => {34 const root = await createRoot();35 .expect(root.innerText).eql('Hello World!');36});37import { Selector, t } from 'testcafe';38class Page {39 constructor () {40 this.nameInput = Selector('#developer-name');41 this.triedTestCafeCheckbox = Selector('#tried-test-cafe');42 this.submitButton = Selector('#submit-button');43 }44}45const page = new Page();46test('My first test', async t => {47 .typeText(page.nameInput, 'John

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 const secondLabel = Selector('label').withText('Second Option').createRoot('#main');4 await t.click(secondLabel);5});6import { Selector } from 'testcafe';7test('My first test', async t => {8 const secondLabel = Selector('label').withText('Second Option');9 await t.click(secondLabel);10});11import { ClientFunction } from 'testcafe';12test('My first test', async t => {13 const getWindowLocation = ClientFunction(() => window.location);14 const location = await getWindowLocation();15});16import { RequestLogger } from 'testcafe';17test('My first test', async t => {18 .click('#send-request')19 .expect(logger.contains(r => r.response.statusCode === 200)).ok();20});21import { RequestMock } from 'testcafe';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { t } from 'testcafe';2import { createRoot } from 'testcafe-react-selectors';3const rootSelector = createRoot('#root');4test('My test', async () => {5 .click(rootSelector.find('button').withText('Click me'));6});7import { Selector } from 'testcafe';8import { ReactSelector } from 'testcafe-react-selectors';9test('My test', async t => {10 const component = ReactSelector('MyComponent');11 await t.expect(component.exists).ok();12});13import { Selector } from 'testcafe';14import { ReactSelector } from 'testcafe-react-selectors';15test('My test', async t => {16 const component = ReactSelector('MyComponent');17 .expect(component.find('NestedComponent').exists).ok()18 .expect(component.find('NestedComponent').find('NestedComponent').exists).ok();19});20import { Selector } from 'testcafe';21import { ReactSelector } from 'testcafe-react-selectors';22test('My test', async t => {23 .expect(ReactSelector('MyComponent').withProps({ prop1: 'value1', prop2: 'value2' }).exists).ok()24 .expect(ReactSelector('MyComponent').withProps({ prop1: 'value1', prop2: 'value3' }).exists).notOk();25});26import { Selector } from 'testcafe';27import { ReactSelector } from 'testcafe-react-selectors';28test('My test', async t => {29 .expect(ReactSelector('MyComponent').withState({ state1: 'value1', state2: 'value2' }).exists).ok()

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from "testcafe";2test("My Test", async t => {3 const root = Selector(createRoot).addCustomMethods({4 test: () => {}5 });6 await t.click(root);7});8import { Selector } from "testcafe";9export const createRoot = Selector(() => {10 return document.getElementById("root");11});

Full Screen

Using AI Code Generation

copy

Full Screen

1import {Selector, t} from 'testcafe'2import {createRoot, createReactSelector} from 'testcafe-react-selectors'3const root = createRoot()4test('React test', async t => {5 const element = root.findReact('MyComponent')6 .expect(element.exists).ok()7 .expect(element.props('prop1')).eql('value1')8 .expect(element.props('prop2')).eql('value2')9 .expect(element.props('prop3')).eql('value3')10 .expect(element.state('state1')).eql('value1')11 .expect(element.state('state2')).eql('value2')12 .expect(element.state('state3')).eql('value3')13 .expect(element.text()).eql('text')14 .expect(element.getReact(({props, state}) => props.prop1)).eql('value1')15})16test('React test', async t => {17 const element = createReactSelector('MyComponent')18 .expect(element.exists).ok()19 .expect(element.props('prop1')).eql('value1')20 .expect(element.props('prop2')).eql('value2')21 .expect(element.props('prop3')).eql('value3')22 .expect(element.state('state1')).eql('value1')23 .expect(element.state('state2')).eql('value2')24 .expect(element.state('state3')).eql('value3')25 .expect(element.text()).eql('text')26 .expect(element.getReact(({props, state}) => props.prop1)).eql('value1')27})28test('React test', async t => {29 const element = createReactSelector('MyComponent')30 .expect(element.exists).ok()31 .expect(element.props('prop1')).eql('value1')32 .expect(element.props('prop2')).eql('value2')33 .expect(element.props('prop3')).eql('value3')34 .expect(element.state('state1')).eql('value

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcafe automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful