Best JavaScript code snippet using qawolf
codegen.spec.js
Source:codegen.spec.js
...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 });...
ReactDOMRoot-test.js
Source:ReactDOMRoot-test.js
...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});
ReactDOMRoot-test.internal.js
Source:ReactDOMRoot-test.internal.js
...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});
client.js
Source:client.js
...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}...
Using AI Code Generation
1const { createRoot } = require('qawolf');2const root = createRoot();3const { create } = require('qawolf');4const browser = await create();5const { chromium } = require('playwright');6const browser = await chromium.launch();7const context = await browser.newContext();8const page = await context.newPage();9const { chromium } = require('playwright');10const browser = await chromium.launch();11const context = await browser.newContext();12const page = await context.newPage();13const root = page;14const { chromium } = require('playwright');15const browser = await chromium.launch();16const context = await browser.newContext();17const page = await context.newPage();18const root = page;19const { chromium } = require('playwright');20const browser = await chromium.launch();21const context = await browser.newContext();22const page = await context.newPage();23const puppeteer = require('puppeteer');24const browser = await puppeteer.launch();25const page = await browser.newPage();26const root = page;27const puppeteer = require('puppeteer');28const browser = await puppeteer.launch();29const page = await browser.newPage();30const puppeteer = require('puppeteer');31const browser = await puppeteer.launch();32const page = await browser.newPage();33const root = page;34const puppeteer = require('puppeteer');35const browser = await puppeteer.launch();36const page = await browser.newPage();37const puppeteer = require('puppeteer');38const browser = await puppeteer.launch();39const page = await browser.newPage();40const root = page;41const puppeteer = require('puppeteer');42const browser = await puppeteer.launch();43const page = await browser.newPage();44const puppeteer = require('puppeteer');45const browser = await puppeteer.launch();46const page = await browser.newPage();
Using AI Code Generation
1const { createRoot } = require("qawolf");2const root = createRoot();3const { create } = require("qawolf");4const browser = await create();5const { create } = require("qawolf");6const { create } = require("qawolf");7const browser = await create({ browser: "firefox" });8const { create } = require("qawolf");9const { create } = require("qawolf");10const { create } = require("qawolf");11const { create } = require("qawolf");12const { create } = require("qawolf");13const { create } = require("qawolf");14const { create } = require("qawolf");15const { create } = require("qawolf");16const { create } = require("qawolf");
Using AI Code Generation
1const { createRoot } = require("qawolf");2const root = createRoot();3const { create } = require("qawolf");4const browser = await create({ name: "test" });5const { create } = require("qawolf");6const browser = await create({ name: "test" });7const { create } = require("qawolf");8const browser = await create({ name: "test" });9const { create } = require("qawolf");10const browser = await create({ name: "test" });11const { create } = require("qawolf");12const browser = await create({ name: "test" });13const { create } = require("qawolf");14const browser = await create({ name: "test" });15const { create } = require("qawolf");16const browser = await create({ name: "test" });17const { create } = require("qawolf");18const browser = await create({ name: "test" });19const { create } = require("qawolf");20const browser = await create({ name: "test" });21const { create } = require("qawolf");22const browser = await create({ name: "test" });23const { create } = require("qawolf");24const browser = await create({ name: "test" });25const { create } = require("qawolf");26const browser = await create({ name: "test" });27const { create } = require("qawolf");28const browser = await create({ name: "test" });29const { create } = require("qawolf");30const browser = await create({ name: "test" });
Using AI Code Generation
1const { createRoot } = require("qawolf");2const puppeteer = require("puppeteer");3const qawolf = require("qawolf");4const { create } = require("qawolf");5const { launch } = require("puppeteer");6const { create } = require("qawolf");7const { createRoot } = require("qawolf");8const { launch } = require("puppeteer");9const { createRoot } = require("qawolf");10const { launch } = require("puppeteer");11const { create } = require("qawolf");12const { createRoot } = require("qawolf");13const { launch } = require("puppeteer");14const { createRoot } = require("qawolf");15const { launch } = require("puppeteer");16const { create } = require("qawolf");17const { createRoot } = require("qawolf");18const { createRoot } = require("qawolf");19const { launch } = require("puppeteer");20const { create } = require("qawolf");21const { createRoot } = require("qawolf");22const { launch } = require("puppeteer");23const { create } = require("qaw
Using AI Code Generation
1const { createRoot } = require("qawolf");2const root = createRoot();3const { create } = root;4const { create } = root;5const { createRoot } = require("qawolf");6const root = createRoot();7const { create } = root;8const { create } = root;9const selector = create("input");10selector.select();11const { createRoot } = require("qawolf");12const root = createRoot();13const { create } = root;14const { create } = root;15const selector = create("input");16selector.select();17await selector.click();
Using AI Code Generation
1const { createRoot } = require("qawolf");2const root = createRoot();3root.type("input[type='text']", "hello world");4root.type("input[type='password']", "password");5root.click("button[type='submit']");6root.close();7{8 "scripts": {9 },10 "dependencies": {11 }12}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!