How to use defineComponent method in Playwright Internal

Best JavaScript code snippet using playwright-internal

expr.spec.js

Source:expr.spec.js Github

copy

Full Screen

...3 expect(value).toBe(expectValue);4 return value;5 }6 it("bool true", function () {7 var MyComponent = san.defineComponent({8 template: '<b>{{val1 | tobe(true)}}</b>',9 filters: {tobe: tobeFilter}10 });11 var myComponent = new MyComponent();12 myComponent.data.set('val1', true);13 var wrap = document.createElement('div');14 document.body.appendChild(wrap);15 myComponent.attach(wrap);16 myComponent.dispose();17 document.body.removeChild(wrap);18 });19 it("bool false", function () {20 var MyComponent = san.defineComponent({21 template: '<b>{{val1 | tobe(false)}}</b>',22 filters: {tobe: tobeFilter}23 });24 var myComponent = new MyComponent();25 myComponent.data.set('val1', false);26 var wrap = document.createElement('div');27 document.body.appendChild(wrap);28 myComponent.attach(wrap);29 myComponent.dispose();30 document.body.removeChild(wrap);31 });32 it("null", function () {33 var MyComponent = san.defineComponent({34 template: '<a><b s-if="nullValue === null">b</b></a>'35 });36 var myComponent = new MyComponent({ data: { nullValue: null }});37 var wrap = document.createElement('div');38 document.body.appendChild(wrap);39 myComponent.attach(wrap);40 expect(wrap.getElementsByTagName('b').length).toBe(1);41 myComponent.dispose();42 document.body.removeChild(wrap);43 });44 it("unary -", function () {45 var MyComponent = san.defineComponent({46 template: '<b>{{-val1 | tobe(-10)}}</b>',47 filters: { tobe: tobeFilter }48 });49 var myComponent = new MyComponent();50 myComponent.data.set('val1', 10);51 var wrap = document.createElement('div');52 document.body.appendChild(wrap);53 myComponent.attach(wrap);54 myComponent.dispose();55 document.body.removeChild(wrap);56 });57 it("unary !", function () {58 var MyComponent = san.defineComponent({59 template: '<b>{{!val1 | tobe(false)}}</b>',60 filters: {tobe: tobeFilter}61 });62 var myComponent = new MyComponent();63 myComponent.data.set('val1', 10);64 var wrap = document.createElement('div');65 document.body.appendChild(wrap);66 myComponent.attach(wrap);67 myComponent.dispose();68 document.body.removeChild(wrap);69 });70 it("unary !!", function () {71 var MyComponent = san.defineComponent({72 template: '<b>{{!!val1 | tobe(true)}}</b>',73 filters: {tobe: tobeFilter}74 });75 var myComponent = new MyComponent();76 myComponent.data.set('val1', 10);77 var wrap = document.createElement('div');78 document.body.appendChild(wrap);79 myComponent.attach(wrap);80 myComponent.dispose();81 document.body.removeChild(wrap);82 });83 it("tertiary when cond true", function () {84 var MyComponent = san.defineComponent({85 template: '<b>{{a+b-c ? v1 + v2 : v3 + v4 | tobe(\'hello erik\')}}</b>',86 filters: {tobe: tobeFilter},87 initData: function () {88 return {89 a: 1,90 b: 2,91 c: 2,92 v1: 'hello ',93 v2: 'erik',94 v3: 'bye ',95 v4: 'moon'96 }97 }98 });99 var myComponent = new MyComponent();100 var wrap = document.createElement('div');101 document.body.appendChild(wrap);102 myComponent.attach(wrap);103 myComponent.dispose();104 document.body.removeChild(wrap);105 });106 it("tertiary when cond false", function () {107 var MyComponent = san.defineComponent({108 template: '<b>{{a+b-c ? v1 + v2 : v3 + v4 | tobe(\'bye moon\')}}</b>',109 filters: {tobe: tobeFilter},110 initData: function () {111 return {112 a: 1,113 b: 2,114 c: 3,115 v1: 'hello ',116 v2: 'erik',117 v3: 'bye ',118 v4: 'moon'119 }120 }121 });122 var myComponent = new MyComponent();123 var wrap = document.createElement('div');124 document.body.appendChild(wrap);125 myComponent.attach(wrap);126 myComponent.dispose();127 document.body.removeChild(wrap);128 });129 it("binary number +", function () {130 var MyComponent = san.defineComponent({131 template: '<b>{{num1 + num2 | tobe(4)}}</b>',132 filters: {tobe: tobeFilter}133 });134 var myComponent = new MyComponent();135 myComponent.data.set('num1', 1);136 myComponent.data.set('num2', 3);137 var wrap = document.createElement('div');138 document.body.appendChild(wrap);139 myComponent.attach(wrap);140 myComponent.dispose();141 document.body.removeChild(wrap);142 });143 it("binary string +", function () {144 var MyComponent = san.defineComponent({145 template: '<b>{{val1 + val2 | tobe("hello varsha")}}</b>',146 filters: {tobe: tobeFilter}147 });148 var myComponent = new MyComponent();149 myComponent.data.set('val1', 'hello ');150 myComponent.data.set('val2', 'varsha');151 var wrap = document.createElement('div');152 document.body.appendChild(wrap);153 myComponent.attach(wrap);154 myComponent.dispose();155 document.body.removeChild(wrap);156 });157 it("binary number -", function () {158 var MyComponent = san.defineComponent({159 template: '<b>{{val1 - val2 | tobe(4)}}</b>',160 filters: {tobe: tobeFilter}161 });162 var myComponent = new MyComponent();163 myComponent.data.set('val1', 5);164 myComponent.data.set('val2', 1);165 var wrap = document.createElement('div');166 document.body.appendChild(wrap);167 myComponent.attach(wrap);168 myComponent.dispose();169 document.body.removeChild(wrap);170 });171 it("binary number *", function () {172 var MyComponent = san.defineComponent({173 template: '<b>{{val1 * val2 | tobe(150)}}</b>',174 filters: {tobe: tobeFilter}175 });176 var myComponent = new MyComponent();177 myComponent.data.set('val1', 5);178 myComponent.data.set('val2', 30);179 var wrap = document.createElement('div');180 document.body.appendChild(wrap);181 myComponent.attach(wrap);182 myComponent.dispose();183 document.body.removeChild(wrap);184 });185 it("binary number /", function () {186 var MyComponent = san.defineComponent({187 template: '<b>{{val1 / val2 | tobe(6)}}</b>',188 filters: {tobe: tobeFilter}189 });190 var myComponent = new MyComponent();191 myComponent.data.set('val1', 30);192 myComponent.data.set('val2', 5);193 var wrap = document.createElement('div');194 document.body.appendChild(wrap);195 myComponent.attach(wrap);196 myComponent.dispose();197 document.body.removeChild(wrap);198 });199 it("binary number %", function () {200 var MyComponent = san.defineComponent({201 template: '<b>{{val1 % val2 | tobe(2)}}</b>',202 filters: {tobe: tobeFilter}203 });204 var myComponent = new MyComponent();205 myComponent.data.set('val1', 30);206 myComponent.data.set('val2', 7);207 var wrap = document.createElement('div');208 document.body.appendChild(wrap);209 myComponent.attach(wrap);210 myComponent.dispose();211 document.body.removeChild(wrap);212 });213 it("binary number ==", function () {214 var MyComponent = san.defineComponent({215 template: '<b>{{val1 == val2 | tobe(!0)}}</b>',216 filters: {tobe: tobeFilter}217 });218 var myComponent = new MyComponent();219 myComponent.data.set('val1', '');220 myComponent.data.set('val2', 0);221 var wrap = document.createElement('div');222 document.body.appendChild(wrap);223 myComponent.attach(wrap);224 myComponent.dispose();225 document.body.removeChild(wrap);226 });227 it("binary number ===", function () {228 var MyComponent = san.defineComponent({229 template: '<b>{{val1 === val2 | tobe(!1)}}</b>',230 filters: {tobe: tobeFilter}231 });232 var myComponent = new MyComponent();233 myComponent.data.set('val1', '');234 myComponent.data.set('val2', 0);235 var wrap = document.createElement('div');236 document.body.appendChild(wrap);237 myComponent.attach(wrap);238 myComponent.dispose();239 document.body.removeChild(wrap);240 });241 it("binary number !=", function () {242 var MyComponent = san.defineComponent({243 template: '<b>{{val1 != val2 | tobe(!1)}}</b>',244 filters: {tobe: tobeFilter}245 });246 var myComponent = new MyComponent();247 myComponent.data.set('val1', '');248 myComponent.data.set('val2', 0);249 var wrap = document.createElement('div');250 document.body.appendChild(wrap);251 myComponent.attach(wrap);252 myComponent.dispose();253 document.body.removeChild(wrap);254 });255 it("binary number !==", function () {256 var MyComponent = san.defineComponent({257 template: '<b>{{val1 !== val2 | tobe(!0)}}</b>',258 filters: {tobe: tobeFilter}259 });260 var myComponent = new MyComponent();261 myComponent.data.set('val1', '');262 myComponent.data.set('val2', 0);263 var wrap = document.createElement('div');264 document.body.appendChild(wrap);265 myComponent.attach(wrap);266 myComponent.dispose();267 document.body.removeChild(wrap);268 });269 it("binary number >", function () {270 var MyComponent = san.defineComponent({271 template: '<b>{{val1 > val2 | tobe(!0)}}</b>',272 filters: {tobe: tobeFilter}273 });274 var myComponent = new MyComponent();275 myComponent.data.set('val1', 1);276 myComponent.data.set('val2', 0);277 var wrap = document.createElement('div');278 document.body.appendChild(wrap);279 myComponent.attach(wrap);280 myComponent.dispose();281 document.body.removeChild(wrap);282 });283 it("binary number <", function () {284 var MyComponent = san.defineComponent({285 template: '<b>{{val1 < val2 | tobe(!1)}}</b>',286 filters: {tobe: tobeFilter}287 });288 var myComponent = new MyComponent();289 myComponent.data.set('val1', 1);290 myComponent.data.set('val2', 0);291 var wrap = document.createElement('div');292 document.body.appendChild(wrap);293 myComponent.attach(wrap);294 myComponent.dispose();295 document.body.removeChild(wrap);296 });297 it("binary number >=", function () {298 var MyComponent = san.defineComponent({299 template: '<b>{{val1 >= val2 | tobe(!0)}}</b>',300 filters: {tobe: tobeFilter}301 });302 var myComponent = new MyComponent();303 myComponent.data.set('val1', 1);304 myComponent.data.set('val2', 1);305 var wrap = document.createElement('div');306 document.body.appendChild(wrap);307 myComponent.attach(wrap);308 myComponent.dispose();309 document.body.removeChild(wrap);310 });311 it("binary number <=", function () {312 var MyComponent = san.defineComponent({313 template: '<b>{{val1 <= val2 | tobe(!0)}}</b>',314 filters: {tobe: tobeFilter}315 });316 var myComponent = new MyComponent();317 myComponent.data.set('val1', 1);318 myComponent.data.set('val2', 1);319 var wrap = document.createElement('div');320 document.body.appendChild(wrap);321 myComponent.attach(wrap);322 myComponent.dispose();323 document.body.removeChild(wrap);324 });325 it("confuse a + b * c", function () {326 var MyComponent = san.defineComponent({327 template: '<b>{{val1 + val2 * val3 | tobe(23)}}</b>',328 filters: {tobe: tobeFilter}329 });330 var myComponent = new MyComponent();331 myComponent.data.set('val1', 3);332 myComponent.data.set('val2', 4);333 myComponent.data.set('val3', 5);334 var wrap = document.createElement('div');335 document.body.appendChild(wrap);336 myComponent.attach(wrap);337 myComponent.dispose();338 document.body.removeChild(wrap);339 });340 it("confuse a * b + c", function () {341 var MyComponent = san.defineComponent({342 template: '<b>{{val1 * val2 + val3 | tobe(17)}}</b>',343 filters: {tobe: tobeFilter}344 });345 var myComponent = new MyComponent();346 myComponent.data.set('val1', 3);347 myComponent.data.set('val2', 4);348 myComponent.data.set('val3', 5);349 var wrap = document.createElement('div');350 document.body.appendChild(wrap);351 myComponent.attach(wrap);352 myComponent.dispose();353 document.body.removeChild(wrap);354 });355 it("confuse a % b + c", function () {356 var MyComponent = san.defineComponent({357 template: '<b>{{val1 % val2 + val3 | tobe(8)}}</b>',358 filters: {tobe: tobeFilter}359 });360 var myComponent = new MyComponent();361 myComponent.data.set('val1', 3);362 myComponent.data.set('val2', 4);363 myComponent.data.set('val3', 5);364 var wrap = document.createElement('div');365 document.body.appendChild(wrap);366 myComponent.attach(wrap);367 myComponent.dispose();368 document.body.removeChild(wrap);369 });370 it("confuse a * (b + c), parenthesized", function () {371 var MyComponent = san.defineComponent({372 template: '<b>{{val1 * (val2 + val3) | tobe(27)}}</b>',373 filters: {tobe: tobeFilter}374 });375 var myComponent = new MyComponent();376 myComponent.data.set('val1', 3);377 myComponent.data.set('val2', 4);378 myComponent.data.set('val3', 5);379 var wrap = document.createElement('div');380 document.body.appendChild(wrap);381 myComponent.attach(wrap);382 myComponent.dispose();383 document.body.removeChild(wrap);384 });385 it("confuse a * b == c + d", function () {386 var MyComponent = san.defineComponent({387 template: '<b>{{val1 * val2 == val3 + val4 | tobe(!0)}}</b>',388 filters: {tobe: tobeFilter}389 });390 var myComponent = new MyComponent();391 myComponent.data.set('val1', 3);392 myComponent.data.set('val2', 4);393 myComponent.data.set('val3', 5);394 myComponent.data.set('val4', 7);395 var wrap = document.createElement('div');396 document.body.appendChild(wrap);397 myComponent.attach(wrap);398 myComponent.dispose();399 document.body.removeChild(wrap);400 });401 it("confuse a * b <= c + d", function () {402 var MyComponent = san.defineComponent({403 template: '<b>{{val1 * val2 <= val3 + val4 | tobe(!1)}}</b>',404 filters: {tobe: tobeFilter}405 });406 var myComponent = new MyComponent();407 myComponent.data.set('val1', 3);408 myComponent.data.set('val2', 4);409 myComponent.data.set('val3', 5);410 myComponent.data.set('val4', 6);411 var wrap = document.createElement('div');412 document.body.appendChild(wrap);413 myComponent.attach(wrap);414 myComponent.dispose();415 document.body.removeChild(wrap);416 });417 it("confuse a * b <= c + d ? a1 * b1 <= c1 + d1 ? xxx : xxxx : xxx", function () {418 var MyComponent = san.defineComponent({419 template: '<b>{{val1 * val2 <= val3 + val4 ? va1 * va2 <= va3 + va4 ? \'3\' : yno: \'1\' | tobe(\'yno\')}}</b>',420 filters: {tobe: tobeFilter},421 initData: function () {422 return {423 val1: 3,424 val2: 4,425 val3: 7,426 val4: 6,427 va1: 3,428 va2: 4,429 va3: 5,430 va4: 6,431 yno: 'yno'432 }433 }434 });435 var myComponent = new MyComponent();436 var wrap = document.createElement('div');437 document.body.appendChild(wrap);438 myComponent.attach(wrap);439 myComponent.dispose();440 document.body.removeChild(wrap);441 });442 it("confuse a * b <= c + d ? a1 * b1 <= c1 + d1 ? xxx : xxxx : xxx", function () {443 var MyComponent = san.defineComponent({444 template: '<b>{{val1 * val2 <= val3 + val4 ? va1 * va2 <= va3 + va4 ? \'3\' : yno: \'1\' | tobe(\'1\')}}</b>',445 filters: {tobe: tobeFilter},446 initData: function () {447 return {448 val1: 3,449 val2: 4,450 val3: 5,451 val4: 6,452 va1: 3,453 va2: 4,454 va3: 5,455 va4: 6,456 yno: 'yno'457 }458 }459 });460 var myComponent = new MyComponent();461 var wrap = document.createElement('div');462 document.body.appendChild(wrap);463 myComponent.attach(wrap);464 myComponent.dispose();465 document.body.removeChild(wrap);466 });467 it("confuse a * b <= c + d ? a1 * b1 <= c1 + d1 ? xxx : xxxx : xxx", function () {468 var MyComponent = san.defineComponent({469 template: '<b>{{val1 * val2 <= val3 + val4 ? \'1\' : va1 * va2 > va3 + va4 ? \'3\' : yno | tobe(\'3\')}}</b>',470 filters: {tobe: tobeFilter},471 initData: function () {472 return {473 val1: 3,474 val2: 4,475 val3: 5,476 val4: 6,477 va1: 3,478 va2: 4,479 va3: 5,480 va4: 6,481 yno: 'yno'482 }483 }484 });485 var myComponent = new MyComponent();486 var wrap = document.createElement('div');487 document.body.appendChild(wrap);488 myComponent.attach(wrap);489 myComponent.dispose();490 document.body.removeChild(wrap);491 });492 it("no whitespace binary in number literals", function () {493 var MyComponent = san.defineComponent({494 template: '<b>{{1+1|tobe(2)}}</b>',495 filters: { tobe: tobeFilter }496 });497 var myComponent = new MyComponent();498 var wrap = document.createElement('div');499 document.body.appendChild(wrap);500 myComponent.attach(wrap);501 myComponent.dispose();502 document.body.removeChild(wrap);503 });504 it("use san.Data and san.evalExpr", function () {505 var parentData = new san.Data({506 val1: 1,507 val2: 1,...

Full Screen

Full Screen

component-async.spec.js

Source:component-async.spec.js Github

copy

Full Screen

1describe("Component Async", function () {2 it("loaded by promise resolved", function (done) {3 var Label = san.defineComponent({4 template: '<u>{{text}}</u>'5 });6 var loadSuccess;7 var MyComponent = san.defineComponent({8 components: {9 'x-label': san.createComponentLoader(function () {10 return {11 then: function (success) {12 loadSuccess = success;13 }14 };15 })16 },17 template: '<div><x-label text="{{text}}"/><b>bbb</b></div>',18 attached: function () {19 this.nextTick(function () {20 loadSuccess(Label);21 });22 }23 });24 var myComponent = new MyComponent({25 data: {26 text: 'Hello San'27 }28 });29 var wrap = document.createElement('div');30 document.body.appendChild(wrap);31 myComponent.attach(wrap);32 expect(wrap.getElementsByTagName('b').length).toBe(1);33 expect(wrap.getElementsByTagName('u').length).toBe(0);34 setTimeout(function () {35 expect(wrap.getElementsByTagName('u').length).toBe(1);36 expect(wrap.getElementsByTagName('b').length).toBe(1);37 expect(wrap.getElementsByTagName('u')[0].innerHTML).toBe('Hello San');38 myComponent.dispose();39 document.body.removeChild(wrap);40 done();41 }, 500);42 });43 it("loading placeholder", function (done) {44 var Label = san.defineComponent({45 template: '<u>{{text}}</u>'46 });47 var LoadingLabel = san.defineComponent({48 template: '<b>{{text}}</b>'49 });50 var loadSuccess;51 var MyComponent = san.defineComponent({52 components: {53 'x-label': san.createComponentLoader({54 load: function () {55 return {56 then: function (success) {57 loadSuccess = success;58 }59 };60 },61 placeholder: LoadingLabel62 })63 },64 template: '<div><x-label text="{{text}}"/></div>',65 attached: function () {66 this.nextTick(function () {67 loadSuccess(Label);68 });69 }70 });71 var myComponent = new MyComponent({72 data: {73 text: 'Hello San'74 }75 });76 var wrap = document.createElement('div');77 document.body.appendChild(wrap);78 myComponent.attach(wrap);79 expect(wrap.getElementsByTagName('u').length).toBe(0);80 expect(wrap.getElementsByTagName('b').length).toBe(1);81 expect(wrap.getElementsByTagName('b')[0].innerHTML).toBe('Hello San');82 setTimeout(function () {83 expect(wrap.getElementsByTagName('u').length).toBe(1);84 expect(wrap.getElementsByTagName('u')[0].innerHTML).toBe('Hello San');85 expect(wrap.getElementsByTagName('b').length).toBe(0);86 myComponent.dispose();87 document.body.removeChild(wrap);88 done();89 }, 500);90 });91 it("fallback by fallback declaration", function (done) {92 var Label = san.defineComponent({93 template: '<u>{{text}}</u>'94 });95 var LoadingLabel = san.defineComponent({96 template: '<b>{{text}}</b>'97 });98 var FallbackLabel = san.defineComponent({99 template: '<input value="{{text}}"/>'100 });101 var loadFail;102 var loadSuccess;103 var MyComponent = san.defineComponent({104 components: {105 'x-label': san.createComponentLoader({106 load: function () {107 return {108 then: function (success, fail) {109 loadSuccess = success;110 loadFail = fail;111 }112 };113 },114 placeholder: LoadingLabel,115 fallback: FallbackLabel116 })117 },118 template: '<div><x-label text="{{text}}"/></div>',119 attached: function () {120 this.nextTick(function () {121 loadFail();122 });123 }124 });125 var myComponent = new MyComponent({126 data: {127 text: 'Hello San'128 }129 });130 var wrap = document.createElement('div');131 document.body.appendChild(wrap);132 myComponent.attach(wrap);133 expect(wrap.getElementsByTagName('u').length).toBe(0);134 expect(wrap.getElementsByTagName('b').length).toBe(1);135 expect(wrap.getElementsByTagName('b')[0].innerHTML).toBe('Hello San');136 setTimeout(function () {137 expect(wrap.getElementsByTagName('u').length).toBe(0);138 expect(wrap.getElementsByTagName('input').length).toBe(1);139 expect(wrap.getElementsByTagName('input')[0].value).toBe('Hello San');140 expect(wrap.getElementsByTagName('b').length).toBe(0);141 myComponent.data.set('text', 'GoodBye San');142 myComponent.nextTick(function () {143 expect(wrap.getElementsByTagName('input')[0].value).toBe('GoodBye San');144 myComponent.dispose();145 document.body.removeChild(wrap);146 done();147 });148 }, 500);149 });150 it("fallback by promise reject", function (done) {151 var Label = san.defineComponent({152 template: '<u>{{text}}</u>'153 });154 var LoadingLabel = san.defineComponent({155 template: '<b>{{text}}</b>'156 });157 var FallbackLabel = san.defineComponent({158 template: '<input value="{{text}}"/>'159 });160 var loadFail;161 var loadSuccess;162 var MyComponent = san.defineComponent({163 components: {164 'x-label': san.createComponentLoader({165 load: function () {166 return {167 then: function (success, fail) {168 loadSuccess = success;169 loadFail = fail;170 }171 };172 },173 placeholder: LoadingLabel174 })175 },176 template: '<div><x-label text="{{text}}"/></div>',177 attached: function () {178 this.nextTick(function () {179 loadFail(FallbackLabel);180 });181 }182 });183 var myComponent = new MyComponent({184 data: {185 text: 'Hello San'186 }187 });188 var wrap = document.createElement('div');189 document.body.appendChild(wrap);190 myComponent.attach(wrap);191 expect(wrap.getElementsByTagName('u').length).toBe(0);192 expect(wrap.getElementsByTagName('b').length).toBe(1);193 expect(wrap.getElementsByTagName('b')[0].innerHTML).toBe('Hello San');194 setTimeout(function () {195 expect(wrap.getElementsByTagName('u').length).toBe(0);196 expect(wrap.getElementsByTagName('input').length).toBe(1);197 expect(wrap.getElementsByTagName('input')[0].value).toBe('Hello San');198 expect(wrap.getElementsByTagName('b').length).toBe(0);199 myComponent.data.set('text', 'GoodBye San');200 myComponent.nextTick(function () {201 expect(wrap.getElementsByTagName('input')[0].value).toBe('GoodBye San');202 myComponent.dispose();203 document.body.removeChild(wrap);204 done();205 });206 }, 500);207 });208 it("with if", function (done) {209 var Label = san.defineComponent({210 template: '<u>{{text}}</u>'211 });212 var LoadingLabel = san.defineComponent({213 template: '<b>{{text}}</b>'214 });215 var loadSuccess;216 var MyComponent = san.defineComponent({217 components: {218 'x-label': san.createComponentLoader({219 load: function () {220 return {221 then: function (success) {222 loadSuccess = success;223 }224 };225 },226 placeholder: LoadingLabel227 })228 },229 template: '<div><x-label text="{{text}}" s-if="isShow"/></div>'230 });231 var myComponent = new MyComponent({232 data: {233 text: 'Hello San'234 }235 });236 var wrap = document.createElement('div');237 document.body.appendChild(wrap);238 myComponent.attach(wrap);239 expect(wrap.getElementsByTagName('u').length).toBe(0);240 expect(wrap.getElementsByTagName('b').length).toBe(0);241 myComponent.data.set('isShow', true);242 myComponent.nextTick(function () {243 expect(wrap.getElementsByTagName('u').length).toBe(0);244 expect(wrap.getElementsByTagName('b').length).toBe(1);245 expect(wrap.getElementsByTagName('b')[0].innerHTML).toBe('Hello San');246 loadSuccess(Label);247 myComponent.nextTick(function () {248 expect(wrap.getElementsByTagName('u').length).toBe(1);249 expect(wrap.getElementsByTagName('u')[0].innerHTML).toBe('Hello San');250 expect(wrap.getElementsByTagName('b').length).toBe(0);251 myComponent.data.set('isShow', false);252 myComponent.nextTick(function () {253 expect(wrap.getElementsByTagName('u').length).toBe(0);254 expect(wrap.getElementsByTagName('b').length).toBe(0);255 myComponent.data.set('isShow', true);256 myComponent.nextTick(function () {257 expect(wrap.getElementsByTagName('u').length).toBe(0);258 expect(wrap.getElementsByTagName('b').length).toBe(1);259 expect(wrap.getElementsByTagName('b')[0].innerHTML).toBe('Hello San');260 myComponent.nextTick(function () {261 expect(wrap.getElementsByTagName('u').length).toBe(1);262 expect(wrap.getElementsByTagName('u')[0].innerHTML).toBe('Hello San');263 expect(wrap.getElementsByTagName('b').length).toBe(0);264 myComponent.dispose();265 document.body.removeChild(wrap);266 done();267 });268 });269 });270 });271 });272 });273 it("with slot", function (done) {274 var Label = san.defineComponent({275 template: '<u><slot/></u>'276 });277 var LoadingLabel = san.defineComponent({278 template: '<b><slot/></b>'279 });280 var loadSuccess;281 var MyComponent = san.defineComponent({282 components: {283 'x-label': san.createComponentLoader({284 load: function () {285 return {286 then: function (success) {287 loadSuccess = success;288 }289 };290 },291 placeholder: LoadingLabel292 })293 },294 template: '<div><x-label>Hello {{text}}</x-label></div>',295 attached: function () {296 this.nextTick(function () {297 loadSuccess(Label);298 });299 }300 });301 var myComponent = new MyComponent({302 data: {303 text: 'San'304 }305 });306 var wrap = document.createElement('div');307 document.body.appendChild(wrap);308 myComponent.attach(wrap);309 expect(wrap.getElementsByTagName('u').length).toBe(0);310 expect(wrap.getElementsByTagName('b').length).toBe(1);311 expect(wrap.getElementsByTagName('b')[0].innerHTML).toContain('Hello San');312 setTimeout(function () {313 expect(wrap.getElementsByTagName('u').length).toBe(1);314 expect(wrap.getElementsByTagName('u')[0].innerHTML).toContain('Hello San');315 expect(wrap.getElementsByTagName('b').length).toBe(0);316 myComponent.dispose();317 document.body.removeChild(wrap);318 done();319 }, 500);320 });321 it("in slot with slot", function (done) {322 var Label = san.defineComponent({323 template: '<u><slot/></u>'324 });325 var Panel = san.defineComponent({326 template: '<a><slot/></a>'327 })328 var LoadingLabel = san.defineComponent({329 template: '<b><slot/></b>'330 });331 var loadSuccess;332 var MyComponent = san.defineComponent({333 components: {334 'x-panel': Panel,335 'x-label': san.createComponentLoader({336 load: function () {337 return {338 then: function (success) {339 loadSuccess = success;340 }341 };342 },343 placeholder: LoadingLabel344 })345 },346 template: '<div><x-panel><x-label>Hello {{text}}</x-label></x-panel></div>',347 attached: function () {348 this.nextTick(function () {349 loadSuccess(Label);350 });351 }352 });353 var myComponent = new MyComponent({354 data: {355 text: 'San'356 }357 });358 var wrap = document.createElement('div');359 document.body.appendChild(wrap);360 myComponent.attach(wrap);361 var a = wrap.getElementsByTagName('a')[0];362 expect(a.getElementsByTagName('u').length).toBe(0);363 expect(a.getElementsByTagName('b').length).toBe(1);364 expect(a.getElementsByTagName('b')[0].innerHTML).toContain('Hello San');365 setTimeout(function () {366 expect(a.getElementsByTagName('u').length).toBe(1);367 expect(a.getElementsByTagName('u')[0].innerHTML).toContain('Hello San');368 expect(a.getElementsByTagName('b').length).toBe(0);369 myComponent.dispose();370 document.body.removeChild(wrap);371 done();372 }, 500);373 });374 it("with for", function (done) {375 var LI = san.defineComponent({376 template: '<li><b><slot/></b></li>'377 });378 var LoadingLabel = san.defineComponent({379 template: '<li><slot/></li>'380 });381 var loadInvokeCount = 0;382 var loadSuccess;383 var MyComponent = san.defineComponent({384 components: {385 'x-li': san.createComponentLoader({386 load: function () {387 loadInvokeCount++;388 return {389 then: function (success) {390 loadSuccess = success;391 }392 };393 },394 placeholder: LoadingLabel395 })396 },397 template: '<ul><x-li s-for="item in list">Hello {{item}}</x-li></ul>'398 });399 var myComponent = new MyComponent({400 data: {401 list: ['yi', 'er', 'san']402 }403 });404 var wrap = document.createElement('div');405 document.body.appendChild(wrap);406 myComponent.attach(wrap);407 expect(wrap.getElementsByTagName('li').length).toBe(3);408 expect(wrap.getElementsByTagName('b').length).toBe(0);409 expect(loadInvokeCount).toBe(1);410 myComponent.nextTick(function () {411 loadSuccess(LI);412 });413 setTimeout(function () {414 expect(wrap.getElementsByTagName('li').length).toBe(3);415 expect(wrap.getElementsByTagName('b').length).toBe(3);416 expect(wrap.getElementsByTagName('b')[0].innerHTML).toContain('Hello yi');417 expect(wrap.getElementsByTagName('b')[1].innerHTML).toContain('Hello er');418 expect(wrap.getElementsByTagName('b')[2].innerHTML).toContain('Hello san');419 myComponent.dispose();420 document.body.removeChild(wrap);421 done();422 }, 500);423 });424 it("reuse loader", function (done) {425 var loadCount = 0;426 var loadSuccess;427 var loader = san.createComponentLoader({428 load: function () {429 loadCount++;430 return {431 then: function (success) {432 loadSuccess = success;433 }434 };435 },436 placeholder: san.defineComponent({437 template: '<b>{{text}}</b>'438 })439 });440 var Label = san.defineComponent({441 template: '<u>{{text}}</u>'442 });443 var MyComponent = san.defineComponent({444 components: {445 'x-label': loader446 },447 template: '<div><x-label text="{{text}}"/></div>'448 });449 var MyComponent2 = san.defineComponent({450 components: {451 'x-label': loader452 },453 template: '<div><x-label text="{{text}}"/></div>'454 });455 var myComponent = new MyComponent({456 data: {457 text: 'Hello San'458 }459 });460 var myComponent2 = new MyComponent2({461 data: {462 text: 'Bye ER'463 }...

Full Screen

Full Screen

component.js

Source:component.js Github

copy

Full Screen

...4 */5export const defineComponents = [6 `7 import san from 'san';8 export default san.defineComponent({9 temlpate: '<p>Hello {{name}}</p>',10 initData() {11 return {12 name: 'San'13 }14 }15 });16 `,17 `18 import san from 'san';19 let options = {20 initData() {21 return {22 name: 'San'23 }24 }25 };26 options.template = '<p>Hello {{name}}</p>';27 export default san.defineComponent(options);28 `,29 `30 import {defineComponent} from 'san';31 export default defineComponent({32 temlpate: '<p>Hello {{name}}</p>',33 initData() {34 return {35 name: 'San'36 }37 }38 });39 `,40 `41 import {defineComponent as def} from 'san';42 let options = {43 initData() {44 return {45 name: 'San'46 }47 }48 };49 options.template = '<p>Hello {{name}}</p>';50 let defineComp = def;51 export default defineComp(options);52 `,53 `54 import {defineComponent as def} from 'san';55 let options = {56 initData() {57 return {58 name: 'San'59 }60 }61 };62 options.template = '<p>Hello {{name}}</p>';63 let defineComp = def;64 let ComponentConstructor = defineComp(options);65 export default ComponentConstructor;66 `,67 `68 const {defineComponent: def} = require('san');69 let options = {70 initData() {71 return {72 name: 'San'73 }74 }75 };76 options.template = '<p>Hello {{name}}</p>';77 let defineComp = def;78 module.exports = defineComp(options);79 `80];81export const defineComponentWithGlobalSanStoreConnect = [82 `83 import san from 'san';84 import {connect} from 'san-store';85 import './store-action';86 const Comp = san.defineComponent({87 temlpate: '<p>Hello {{name}}</p>',88 initData() {89 return {90 name: 'San'91 }92 }93 });94 const NewComp = connect.san({95 num: 'num'96 })(Comp);97 export default NewComp;98 `,99 `100 import {defineComponent as def} from 'san';101 import sanStore from 'san-store';102 let options = {103 initData() {104 return {105 name: 'San'106 }107 }108 };109 options.template = '<p>Hello {{name}}</p>';110 let defineComp = def;111 let ComponentConstructor = defineComp(options);112 export default sanStore.connect.san({num: 'num'})(ComponentConstructor);113 `,114 `115 const {defineComponent: def} = require('san');116 const {connect} = require('san-store');117 let options = {118 initData() {119 return {120 name: 'San'121 }122 }123 };124 options.template = '<p>Hello {{name}}</p>';125 let defineComp = def;126 module.exports = connect['san']({num: 'num'})(defineComp(options));127 `,128 `129 const {defineComponent: def} = require('san');130 const sanStore = require('san-store');131 let options = {132 initData() {133 return {134 name: 'San'135 }136 }137 };138 options.template = '<p>Hello {{name}}</p>';139 let defineComp = def;140 let connect141 connect = sanStore.connect142 let conn;143 conn = connect144 module.exports = conn['san']({num: 'num'})(defineComp(options));145 `146];147export const defineComponentWithInstantSanStoreConnect = [148 `149 import san from 'san';150 import {connect} from 'san-store';151 import store from './store-action';152 const Comp = san.defineComponent({153 temlpate: '<p>Hello {{name}}</p>',154 initData() {155 return {156 name: 'San'157 }158 }159 });160 let connector = connect.createConnector(store);161 const NewComp = connector({162 num: 'num'163 })(Comp);164 export default NewComp;165 `,166 `167 import san from 'san';168 import {connect} from 'san-store';169 import store from './store-action';170 const Comp = san.defineComponent({171 temlpate: '<p>Hello {{name}}</p>',172 initData() {173 return {174 name: 'San'175 }176 }177 });178 let connector;179 connector = connect.createConnector(store);180 const NewComp = connector({181 num: 'num'182 })(Comp);183 export default NewComp;184 `,185 `186 import {defineComponent as def} from 'san';187 import sanStore from 'san-store';188 import store from './store-action';189 let options = {190 initData() {191 return {192 name: 'San'193 }194 }195 };196 options.template = '<p>Hello {{name}}</p>';197 let defineComp = def;198 let ComponentConstructor = defineComp(options);199 export default sanStore.connect.createConnector(store)({num: 'num'})(ComponentConstructor);200 `,201 `202 const {defineComponent: def} = require('san');203 const sanStore = require('san-store');204 const store = require('./store-action');205 const {createConnector} = sanStore.connect;206 let options = {207 initData() {208 return {209 name: 'San'210 }211 }212 };213 options.template = '<p>Hello {{name}}</p>';214 let defineComp = def;215 module.exports = createConnector(store)({num: 'num'})(defineComp(options));216 `217];218export const classComponents = [219 `220 import san from 'san';221 export default class Comp extends san.Component {222 static template = '<p>Hello {{name}}</p>';223 initData() {224 return {225 name: 'San'226 }227 }228 };229 `,230 `231 import {Component as SanComponent} from 'san';232 class Comp extends SanComponent {233 static template = '<p>Hello {{name}}</p>';234 initData() {235 return {236 name: 'San'237 }238 }239 }240 export default Comp;241 `,242 `243 const {Component: SanComponent} = require('san');244 class Comp extends SanComponent {245 static template = '<p>Hello {{name}}</p>';246 initData() {247 return {248 name: 'San'249 }250 }251 }252 export default Comp;253 `254];255export const classComponentWithGlobalSanStoreConnect = [256 `257 import san from 'san';258 import {connect} from 'san-store';259 import './store-action';260 class Comp extends san.Component {261 static temlpate = '<p>Hello {{name}}</p>';262 initData() {263 return {264 name: 'San'265 }266 }267 }268 const NewComp = connect.san({269 num: 'num'270 })(Comp);271 export default NewComp;272 `,273 `274 import {Component as SanComponent} from 'san';275 import sanStore from 'san-store';276 const connect = sanStore.connect;277 class Comp extends SanComponent {278 initData() {279 return {280 name: 'San'281 }282 }283 };284 Comp.prototype.template = '<p>Hello {{name}}</p>';285 export default connect.san({num: 'num'})(Comp);286 `,287 `288 const {Component: SanComponent} = require('san');289 const {connect} = require('san-store');290 const ParentComponent = SanComponent;291 module.exports = connect.san({num: 'num'})(292 class Comp extends ParentComponent {293 static template = '<p>Hello {{name}}</p>';294 initData() {295 return {296 name: 'San'297 }298 }299 }300 );301 `,302 `303 const sanStore = require('san-store');304 const {Component} = require('san');305 const {306 connect: {307 san308 }309 } = sanStore;310 module.exports = san({num: 'num'})(class Comp extends Component {});311 `312];313export const classComponentWithInstantSanStoreConnect = [314 `315 import san from 'san';316 import {connect} from 'san-store';317 import store from './store-action';318 class Comp extends san.Component {319 static temlpate = '<p>Hello {{name}}</p>';320 initData() {321 return {322 name: 'San'323 }324 }325 }326 let connector = connect.createConnector(store);327 const NewComp = connector({328 num: 'num'329 })(Comp);330 export default NewComp;331 `,332 `333 import {Component as SanComponent} from 'san';334 import sanStore from 'san-store';335 import store from './store-action';336 const connect = sanStore.connect;337 class Comp extends SanComponent {338 initData() {339 return {340 name: 'San'341 }342 }343 };344 Comp.prototype.template = '<p>Hello {{name}}</p>';345 export default connect.createConnector(store)({num: 'num'})(Comp);346 `,347 `348 const {Component: SanComponent} = require('san');349 const {connect} = require('san-store');350 const store = require('./store-action');351 const ParentComponent = SanComponent;352 module.exports = connect.createConnector(store)({num: 'num'})(353 class Comp extends ParentComponent {354 static template = '<p>Hello {{name}}</p>';355 initData() {356 return {357 name: 'San'358 }359 }360 }361 );362 `363];364export const functionComponents = [365 `366 import san from 'san';367 function Comp(options) {368 san.Component(this, options);369 this.data = {370 a: 1371 };372 }373 san.inherits(Comp, san.Component);374 export default Comp;375 `376];377// 非component,可能是store或者其他378export const noComponent = [379 `380 export default san.defineComponent({});381 `,382 `383 import san from 'san';384 const Comp = san.defineComponent({385 template: 'Hello World'386 });387 let comp = new Comp();388 comp.attch(document.body);389 `,390 `391 import san from 'san';392 const a = san['defi' + 'neComponent'].hahaha;393 export default a;394 `,395 `396 import san from 'san';397 import {connect} from 'san-store';398 export default connect;399 `,400 `401 import san from 'san';402 import {connect} from 'san-store';403 import store from './store';404 export default connect.san(store);405 `,406 `407 import san from 'san';408 import sanStore from 'san-store';409 import store from './store';410 export default sanStore['co' + 'nnect']({num: 'num'})(class Com extends san.Component {});411 `,412 `413 import san from 'san';414 import {connect} from 'san-store';415 import store from './store-action';416 class Comp extends san.Component {417 static template = '<p>Hello {{name}}</p>';418 initData() {419 return {420 name: 'San'421 }422 }423 }424 export default connect['s' + 'an']({a: 'a'})(Comp);425 `,426 `427 import san from 'san';428 import {connect} from 'san-store';429 import store from './store';430 const connector = connect.createConnector;431 export default connector({num: 'num'})(class Com extends san.Component {});432 `,433 `434 const sanStore = require('san-store');435 const {Component} = require('san');436 const {437 connect: {438 ['s' + 'an']: er439 }440 } = sanStore;441 module.exports = er({num: 'num'})(class Comp extends Component {});442 `,443 `444 const sanStore = require('san-store');445 const {Component} = require('san');446 const {connector} = doSomething();447 module.exports = connector({num: 'num'})(class Comp extends Component {});448 `,449 `450 const {defineComponent: def} = require('san');451 const sanStore = require('san-store');452 let options = {453 initData() {454 return {455 name: 'San'456 }457 }458 };459 options.template = '<p>Hello {{name}}</p>';460 let defineComp = def;461 let connect462 connect = sanStore['con' + 'nect']463 let conn;464 conn = connect465 module.exports = conn['san']({num: 'num'})(defineComp(options));466 `467];468export const hasCommentComponent = [469 `470 /* san-hmr components */471 export default san.defineComponent({});472 `,473 `474 // san-hmr components475 import san from 'san';476 const Comp = san.defineComponent({477 template: 'Hello World'478 });479 let comp = new Comp();480 comp.attch(document.body);481 `,482 `483 export default san.defineComponent({});484 /* san-hmr components */485 `,486 `487 import san from 'san';488 const Comp = san.defineComponent({489 template: 'Hello World'490 });491 let comp = new Comp();492 comp.attch(document.body);493 // san-hmr components494 `495];496export const hasCommentDisable = [497 `498 /* san-hmr disable */499 import san from 'san';500 function Comp(options) {501 san.Component(this, options);502 this.data = {...

Full Screen

Full Screen

strict-mode-test.js

Source:strict-mode-test.js Github

copy

Full Screen

...14 moduleFor(15 'Strict Mode',16 class extends RenderingTestCase {17 '@test Can use a component in scope'() {18 let Foo = defineComponent({}, 'Hello, world!');19 let Bar = defineComponent({ Foo }, '<Foo/>');20 this.registerComponent('bar', { ComponentClass: Bar });21 this.render('<Bar/>');22 this.assertHTML('Hello, world!');23 this.assertStableRerender();24 }25 '@test Can use a custom helper in scope (in append position)'() {26 let foo = defineSimpleHelper(() => 'Hello, world!');27 let Bar = defineComponent({ foo }, '{{foo}}');28 this.registerComponent('bar', { ComponentClass: Bar });29 this.render('<Bar/>');30 this.assertHTML('Hello, world!');31 this.assertStableRerender();32 }33 '@test Can use a custom modifier in scope'() {34 let foo = defineSimpleModifier((element) => (element.innerHTML = 'Hello, world!'));35 let Bar = defineComponent({ foo }, '<div {{foo}}></div>');36 this.registerComponent('bar', { ComponentClass: Bar });37 this.render('<Bar/>');38 this.assertHTML('<div>Hello, world!</div>');39 this.assertStableRerender();40 }41 '@test Can shadow keywords'() {42 let ifComponent = defineComponent({}, 'Hello, world!');43 let Bar = defineComponent({ if: ifComponent }, '{{#if}}{{/if}}');44 this.registerComponent('bar', { ComponentClass: Bar });45 this.render('<Bar/>');46 this.assertHTML('Hello, world!');47 this.assertStableRerender();48 }49 '@test Can use constant values in ambiguous helper/component position'() {50 let value = 'Hello, world!';51 let Foo = defineComponent({ value }, '{{value}}');52 this.registerComponent('foo', { ComponentClass: Foo });53 this.render('<Foo/>');54 this.assertHTML('Hello, world!');55 this.assertStableRerender();56 }57 '@test Can use inline if and unless in strict mode templates'() {58 let Foo = defineComponent({}, '{{if true "foo" "bar"}}{{unless true "foo" "bar"}}');59 this.registerComponent('foo', { ComponentClass: Foo });60 this.render('<Foo/>');61 this.assertHTML('foobar');62 this.assertStableRerender();63 }64 '@test Can use a dynamic component definition'() {65 let Foo = defineComponent({}, 'Hello, world!');66 let Bar = defineComponent(67 {},68 '<this.Foo/>',69 class extends GlimmerishComponent {70 Foo = Foo;71 }72 );73 this.registerComponent('bar', { ComponentClass: Bar });74 this.render('<Bar/>');75 this.assertHTML('Hello, world!');76 this.assertStableRerender();77 }78 '@test Can use a dynamic component definition (curly)'() {79 let Foo = defineComponent({}, 'Hello, world!');80 let Bar = defineComponent(81 {},82 '{{this.Foo}}',83 class extends GlimmerishComponent {84 Foo = Foo;85 }86 );87 this.registerComponent('bar', { ComponentClass: Bar });88 this.render('<Bar/>');89 this.assertHTML('Hello, world!');90 this.assertStableRerender();91 }92 '@test Can use a dynamic helper definition'() {93 let foo = defineSimpleHelper(() => 'Hello, world!');94 let Bar = defineComponent(95 {},96 '{{this.foo}}',97 class extends GlimmerishComponent {98 foo = foo;99 }100 );101 this.registerComponent('bar', { ComponentClass: Bar });102 this.render('<Bar/>');103 this.assertHTML('Hello, world!');104 this.assertStableRerender();105 }106 '@feature(EMBER_DYNAMIC_HELPERS_AND_MODIFIERS) Can use a curried dynamic helper'() {107 let foo = defineSimpleHelper((value) => value);108 let Foo = defineComponent({}, '{{@value}}');109 let Bar = defineComponent({ Foo, foo }, '<Foo @value={{helper foo "Hello, world!"}}/>');110 this.registerComponent('bar', { ComponentClass: Bar });111 this.render('<Bar/>');112 this.assertHTML('Hello, world!');113 this.assertStableRerender();114 }115 '@feature(EMBER_DYNAMIC_HELPERS_AND_MODIFIERS) Can use a curried dynamic modifier'() {116 let foo = defineSimpleModifier((element, [text]) => (element.innerHTML = text));117 let Foo = defineComponent({}, '<div {{@value}}></div>');118 let Bar = defineComponent({ Foo, foo }, '<Foo @value={{modifier foo "Hello, world!"}}/>');119 this.registerComponent('bar', { ComponentClass: Bar });120 this.render('<Bar/>');121 this.assertHTML('<div>Hello, world!</div>');122 this.assertStableRerender();123 }124 }125 );126 moduleFor(127 'Strict Mode - built ins',128 class extends RenderingTestCase {129 '@test Can use Input'() {130 let Foo = defineComponent({ Input }, '<Input/>');131 this.registerComponent('foo', { ComponentClass: Foo });132 this.render('<Foo/>');133 this.assertComponentElement(this.firstChild, {134 tagName: 'input',135 attrs: {136 type: 'text',137 class: 'ember-text-field ember-view',138 },139 });140 this.assertStableRerender();141 }142 '@test Can use TextArea'() {143 let Foo = defineComponent({ TextArea }, '<TextArea/>');144 this.registerComponent('foo', { ComponentClass: Foo });145 this.render('<Foo/>');146 this.assertComponentElement(this.firstChild, {147 tagName: 'textarea',148 attrs: {149 class: 'ember-text-area ember-view',150 },151 });152 this.assertStableRerender();153 }154 '@test Can use hash'() {155 let Foo = defineComponent(156 { hash },157 '{{#let (hash value="Hello, world!") as |hash|}}{{hash.value}}{{/let}}'158 );159 this.registerComponent('foo', { ComponentClass: Foo });160 this.render('<Foo/>');161 this.assertHTML('Hello, world!');162 this.assertStableRerender();163 }164 '@test Can use array'() {165 let Foo = defineComponent(166 { array },167 '{{#each (array "Hello, world!") as |value|}}{{value}}{{/each}}'168 );169 this.registerComponent('foo', { ComponentClass: Foo });170 this.render('<Foo/>');171 this.assertHTML('Hello, world!');172 this.assertStableRerender();173 }174 '@test Can use concat'() {175 let Foo = defineComponent({ concat }, '{{(concat "Hello" ", " "world!")}}');176 this.registerComponent('foo', { ComponentClass: Foo });177 this.render('<Foo/>');178 this.assertHTML('Hello, world!');179 this.assertStableRerender();180 }181 '@test Can use get'() {182 let Foo = defineComponent(183 { hash, get },184 '{{#let (hash value="Hello, world!") as |hash|}}{{(get hash "value")}}{{/let}}'185 );186 this.registerComponent('foo', { ComponentClass: Foo });187 this.render('<Foo/>');188 this.assertHTML('Hello, world!');189 this.assertStableRerender();190 }191 '@test Can use on and fn'(assert) {192 assert.expect(1);193 let handleClick = (value) => {194 assert.equal(value, 123);195 };196 let Foo = defineComponent(197 { on, fn, handleClick },198 '<button {{on "click" (fn handleClick 123)}}>Click</button>'199 );200 this.registerComponent('foo', { ComponentClass: Foo });201 this.render('<Foo/>');202 this.click('button');203 }204 }205 );206 moduleFor(207 'Strict Mode - LinkTo',208 class extends ApplicationTestCase {209 '@test Can use LinkTo'() {210 let Foo = defineComponent({ LinkTo }, '<LinkTo @route="index">Index</LinkTo>');211 this.addComponent('foo', { ComponentClass: Foo });212 this.addTemplate('index', `<Foo/>`);213 return this.visit('/').then(() => {214 this.assertComponentElement(this.firstChild, {215 tagName: 'a',216 attrs: { href: '/', class: 'active ember-view' },217 content: 'Index',218 });219 });220 }221 }222 );...

Full Screen

Full Screen

modularity-script.js

Source:modularity-script.js Github

copy

Full Screen

1//脚本加载顺序2//1---Cocos2d引擎3//2---插件脚本(有多个的话按项目中的路径字母顺序一次加载)4//3---普通脚本(打包后只有一个文件,内部按require的依赖顺序依次初始化)5//每一个单独的脚本文件就构成一个模块6//每个模块都是一个单独的作用域7//以同步的require方法来引用其它模块8//设置module.exports为导出的变量9//1---require(name)---引用模块10//参数name(String)---模块的文件名,不包含路径,不包含后缀,大小写敏感11//返回值---require返回被模块导出的对象12//游戏开始时会自动require所有脚本,这时每个模块内部定义的代码就会被执行一次,之后无论又被require几次,返回的始终是同一份实例13var DefineComponent = require('define-component');14var DefineJavascript = require('define-javascript');15var DefineComponentAndJavascript = require('define-component-and-javascript');16var Exports = require('exports');17var EncapsulationPrivateVariable = require('encapsulation-private-variable');18//2---定义模块19//2.1---定义组件20//当在脚本中声明了一个组件,Creator会默认把它导出,其它脚本直接直接require这个模块就能使用这个组件21cc.Class({22 extends: cc.Component,23 properties: {24 },25 onLoad() {26 //访问组件模块---DefineComponent本身是一个构造函数27 console.log('typeof DefineComponent = ' + typeof DefineComponent); //function 28 var defineComponent = new DefineComponent();29 console.log('DefineComponent introduce = ' + defineComponent.introduce); //defineCompent30 //访问普通JavaScript模块31 console.log('DefineJavascript introduce = ' + DefineJavascript.introduce); //defineJavascript32 console.log('Exports introduce = ' + Exports.introduce); //exports33 Exports.funcA(); //funcA34 console.log('DefineComponentAndJavascript javascript introduce = ' + DefineComponentAndJavascript.javascript.introduce); //javascript35 var component = new DefineComponentAndJavascript.component();36 console.log('DefineComponentAndJavascript component introduce = ' + component.introduce); //component37 console.log('EncapsulationPrivateVariable data = ' + EncapsulationPrivateVariable.data); //undefined 38 EncapsulationPrivateVariable.setData('msg');39 console.log('EncapsulationPrivateVariable getData() = ' + EncapsulationPrivateVariable.getData()); //msg 40 },41 // start () {42 // },43 // update (dt) {},44});45//2.2---定义普通JavaScript模块46// var config = {47// name: 'config'48// };49// module.exports = config;50//module.expors默认是一个空对象({}),可以直接往里面增加新的字段51//等价于52// module.exports.config = {53// name: 'config'54// };...

Full Screen

Full Screen

constructor_spec.js

Source:constructor_spec.js Github

copy

Full Screen

...18 }19 it('exports a define function', function () {20 expect(typeof defineComponent).toBe('function');21 });22 it('defineComponent() should return a component constructor', function () {23 var TestComponent = defineComponent(testComponent);24 expect(typeof TestComponent).toBe('function');25 expect(typeof TestComponent.attachTo).toBe('function');26 expect(TestComponent.prototype.testVal).toBe(1066);27 });28 it('has standard methods', function () {29 var TestComponent = defineComponent(testComponent);30 expect(typeof TestComponent.prototype.on).toBe('function');31 expect(typeof TestComponent.prototype.off).toBe('function');32 expect(typeof TestComponent.prototype.trigger).toBe('function');33 });34 it('can describe itself', function () {35 var TestComponent = defineComponent(testComponent, withGoodDefaults);36 expect(TestComponent.toString()).toBe('testComponent, withGoodDefaults');37 });38 it('adds core defaults', function () {39 var TestComponent = defineComponent(testComponentDefaultAttrs);40 var instance = new TestComponent(document.body);41 expect(instance.attr.core).toBe(35);42 TestComponent.teardownAll();43 });44 it('throws error if required attr not specified', function () {45 var TestComponent = defineComponent(testComponentDefaultAttrsRequired);46 expect(function () {47 var instance = new TestComponent(document.body);48 }).toThrow('Required attribute "req" not specified in attachTo for component "testComponentDefaultAttrsRequired".');49 TestComponent.teardownAll();50 });51 it("doesn't throw error if required attr is specified", function () {52 var TestComponent = defineComponent(testComponentDefaultAttrsRequired);53 expect(function () {54 var instance = new TestComponent(document.body, { req: 'hello' });55 }).not.toThrow();56 TestComponent.teardownAll();57 });58 it("doesn't attach to empty jQuery objects", function () {59 var TestComponent = defineComponent(testComponentDefaultAttrs);60 var trouble = function () {61 new TestComponent();62 };63 expect(trouble).toThrow(new Error("Component needs a node"));64 });65 it('adds mixin defaults', function () {66 var TestComponent = defineComponent(testComponent, withGoodDefaults);67 var instance = new TestComponent(document.body);68 expect(instance.attr.extra).toBe(38);69 TestComponent.teardownAll();70 });71 it('adds core and mixin defaults', function () {72 var TestComponent = defineComponent(testComponentDefaultAttrs, withGoodDefaults);73 var instance = new TestComponent(document.body);74 expect(instance.attr.core).toBe(35);75 expect(instance.attr.extra).toBe(38);76 TestComponent.teardownAll();77 });78 it('throws error when core and mixin defaults overlap', function () {79 expect(function () {80 defineComponent(testComponentDefaultAttrs, withBadDefaults);81 }).toThrow("utils.push attempted to overwrite 'core' while running in protected mode");82 });83 });...

Full Screen

Full Screen

migrateComponentType.js

Source:migrateComponentType.js Github

copy

Full Screen

1// `shims-vue.d.ts` for Vue 3, generated by CLI 4.5.0-4.5.6, uses the following declaration:2// `component: ReturnType<typeof defineComponent>`3// So needs to update to:4// `component: DefineComponent`5module.exports = function migrateComponentType (file, api) {6 const j = api.jscodeshift7 const root = j(file.source)8 const useDoubleQuote = root.find(j.StringLiteral).some(({ node }) => node.extra.raw.startsWith('"'))9 const tsmodule = root.find(j.TSModuleDeclaration, {10 id: {11 value: '*.vue'12 }13 })14 const componentDecl = tsmodule.find(j.VariableDeclarator, {15 id: {16 name: 'component',17 typeAnnotation: {18 typeAnnotation: {19 typeName: {20 name: 'ReturnType'21 },22 typeParameters: {23 params: {24 0: {25 exprName: {26 name: 'defineComponent'27 }28 }29 }30 }31 }32 }33 }34 })35 if (componentDecl.length !== 1) {36 return file.source37 }38 // update the component type39 componentDecl.forEach(({ node }) => {40 node.id.typeAnnotation = j.tsTypeAnnotation(41 j.tsTypeReference(42 j.identifier('DefineComponent'),43 j.tsTypeParameterInstantiation([44 j.tsTypeLiteral([]),45 j.tsTypeLiteral([]),46 j.tsAnyKeyword()47 ])48 )49 )50 })51 // insert DefineComponent type import52 const importDeclFromVue = tsmodule.find(j.ImportDeclaration, {53 source: {54 value: 'vue'55 }56 })57 importDeclFromVue58 .get(0)59 .node.specifiers.push(j.importSpecifier(j.identifier('DefineComponent')))60 // remove defineComponent import if unused61 const defineComponentUsages = tsmodule62 .find(j.Identifier, { name: 'defineComponent' })63 .filter((identifierPath) => {64 const parent = identifierPath.parent.node65 // Ignore the import specifier66 if (67 j.ImportDefaultSpecifier.check(parent) ||68 j.ImportSpecifier.check(parent) ||69 j.ImportNamespaceSpecifier.check(parent)70 ) {71 return false72 }73 return true74 })75 if (defineComponentUsages.length === 0) {76 tsmodule77 .find(j.ImportSpecifier, {78 local: {79 name: 'defineComponent'80 }81 })82 .remove()83 }84 return root.toSource({85 lineTerminator: '\n',86 quote: useDoubleQuote ? 'double' : 'single'87 })88}...

Full Screen

Full Screen

components.js

Source:components.js Github

copy

Full Screen

1import { Types, defineComponent } from "bitecs";2const Vector3 = { x: Types.f32, y: Types.f32, z: Types.f32 };3const MaxCurrent = { max: Types.i16, current: Types.i16 };4export const Ai = defineComponent();5export const Attack = defineComponent(MaxCurrent);6export const Blocking = defineComponent();7export const Body = defineComponent({ slots: [Types.eid, 5] });8export const Burning = defineComponent();9export const Broken = defineComponent();10export const Damage = defineComponent(MaxCurrent);11export const Dead = defineComponent();12export const Droppable = defineComponent();13export const Durability = defineComponent(MaxCurrent);14export const Effects = defineComponent({15 Health: Types.i16,16 Strength: Types.i16,17});18export const FireStarter = defineComponent();19export const Flammable = defineComponent();20export const Forgettable = defineComponent();21// FovDistance and FovRange should use maxCurrent22export const FovDistance = defineComponent({ dist: Types.ui8 });23export const FovRange = defineComponent({ dist: Types.ui8 });24export const Health = defineComponent(MaxCurrent);25export const Intelligence = defineComponent(MaxCurrent);26export const InFov = defineComponent();27export const Inventory = defineComponent({ slots: [Types.eid, 24] });28export const Legendable = defineComponent();29export const Lumens = defineComponent(MaxCurrent);30export const Beam = defineComponent(MaxCurrent);31export const Liquid = defineComponent();32export const Lux = defineComponent(MaxCurrent);33export const MoveTo = defineComponent(Vector3);34export const OnCurrentMap = defineComponent();35export const Opaque = defineComponent();36export const BelongsTo = defineComponent({ eid: Types.eid });37export const Pickupable = defineComponent();38export const PC = defineComponent();39export const Position = defineComponent(Vector3);40export const ResistBurning = defineComponent(MaxCurrent);41export const Revealed = defineComponent();42export const Show = defineComponent();43export const Stairs = defineComponent({ toZ: Types.ui8 });44export const Strength = defineComponent(MaxCurrent);45export const Velocity = defineComponent(Vector3);46export const Wieldable = defineComponent();47export const Wielding = defineComponent({ slot: Types.eid });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { defineComponent } = require('@playwright/test');2const { test } = require('@playwright/test');3defineComponent('MyComponent', (name, options) => {4 test(name, async ({ page }) => {5 expect(await page.innerText('h1')).toBe('Playwright');6 });7});8test.use({9});10test('MyComponent', async ({ baseURL, page }) => {11 await page.goto(baseURL);12 expect(await page.innerText('h1')).toBe('Playwright');13});14test('MyComponent', async ({ baseURL, page }) => {15 await page.goto(baseURL);16 expect(await page.innerText('h1')).toBe('Playwright');17});18test('MyComponent', async ({ baseURL, page }) => {19 await page.goto(baseURL);20 expect(await page.innerText('h1')).toBe('Playwright');21});22test('MyComponent', async ({ baseURL, page }) => {23 await page.goto(baseURL);24 expect(await page.innerText('h1')).toBe('Playwright');25});26test('MyComponent', async ({ baseURL, page }) => {27 await page.goto(baseURL);28 expect(await page.innerText('h1')).toBe('Playwright');29});30test('MyComponent', async ({ baseURL, page }) => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { defineComponent } = require('@playwright/test');2const { test } = defineComponent({3 use: { page: 'Page' },4 test: async ({ page }) => {5 }6});7test('test', async ({ page }) => {8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { defineComponent } = require('playwright');2const { defineComponent } = require('playwright');3const { defineComponent } = require('playwright');4const { defineComponent } = require('playwright');5const { defineComponent } = require('playwright');6const { defineComponent } = require('playwright');7const { defineComponent } = require('playwright');8const { defineComponent } = require('playwright');9const { defineComponent } = require('playwright');10const { defineComponent } = require('playwright');11const { defineComponent } = require('playwright');12const { defineComponent } = require('playwright');13const { defineComponent } = require('playwright');14const { defineComponent } = require('playwright');15const { defineComponent } = require('playwright');16const { defineComponent } = require('playwright');17const { defineComponent } = require('playwright');18const { defineComponent } = require('playwright');19const { defineComponent } = require('playwright');20const { defineComponent } = require('playwright');21const { defineComponent } = require('playwright');22const { defineComponent } = require('playwright');23const { defineComponent } = require('playwright');24const { defineComponent } = require('playwright');25const { defineComponent } = require('playwright');26const { defineComponent } = require('playwright');27const { defineComponent } = require('playwright');28const { defineComponent } = require('playwright');29const { defineComponent } = require('playwright');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { defineComponent } = require('@playwright/test');2defineComponent('MyComponent', async ({ page }, name) => {3 await page.click('text=Click me');4 await page.fill('input', name);5});6const { test } = require('@playwright/test');7test('My test', async ({ page, MyComponent }) => {8 await MyComponent('John Doe');9});10### defineComponent(name, callback)11const { defineComponent } = require('@playwright/test');12defineComponent('MyComponent', async ({ page }, name) => {13 await page.click('text=Click me');14 await page.fill('input', name);15});16const { test } = require('@playwright/test');17test('My test', async ({ page, MyComponent }) => {18 await MyComponent('John Doe');19});20const { defineComponent } = require('@playwright/test');21defineComponent('MyComponent', async ({ page }, name, age) => {22 await page.click('text=Click me');23 await page.fill('input', name);24 await page.fill('input', age);25});26const { test } = require('@playwright/test');27test('My test', async ({ page, MyComponent }) => {28 await MyComponent('John Doe', 20);29});30const { defineComponent } = require('@playwright/test');31defineComponent('MyComponent', async ({ page }, name, age) => {32 await page.click('text=Click me');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { defineComponent } = require('@playwright/test');2defineComponent('test', async ({ page }, use) => {3 await use(page);4});5import { test } from './test';6test.describe('Test', () => {7 test('test', async ({ test }) => {8 });9});10import { test } from './test';11test.describe('Test', () => {12 test('test', async ({ test }) => {13 });14});15import { test } from './test';16test.describe('Test', () => {17 test('test', async ({ test }) => {18 });19});20import { test } from './test';21test.describe('Test', () => {22 test('test', async ({ test }) => {23 });24});25import { test } from './test';26test.describe('Test', () => {27 test('test', async ({ test }) => {28 });29});30import { test } from './test';31test.describe('Test', () => {32 test('test', async ({ test }) => {33 });34});35import { test } from './test';36test.describe('Test', () => {37 test('test', async ({ test }) => {38 });39});40import { test } from './test';41test.describe('Test', () => {42 test('test', async ({ test }) => {43 });44});45import { test } from './test';46test.describe('Test', () => {47 test('test', async ({ test }) => {48 });49});50import { test } from './test';51test.describe('Test', ()

Full Screen

Using AI Code Generation

copy

Full Screen

1const { defineComponent } = require('@playwright/test');2const { chromium } = require('playwright');3const myComponent = defineComponent({4 async action({ page }, name) {5 await page.fill('input[name="name"]', name);6 await page.click('text=Submit');7 await page.waitForNavigation();8 }9});10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 await myComponent.action(page, 'John Doe');15 await page.screenshot({ path: `example.png` });16 await browser.close();17})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { defineComponent } = require('@playwright/test');2module.exports = defineComponent({3 use: {4 myAction: async ({ page }, name) => {5 await page.click(`text=${name}`);6 }7 }8});9const { test, expect } = require('@playwright/test');10const MyComponent = require('./test.js');11test('test', async ({ page }) => {12 await MyComponent.myAction('Docs');13 expect(await page.innerText('.navbar__inner .navbar__title')).toBe('Docs');14});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { defineComponent } = require('@playwright/test')2module.exports = defineComponent({3})4### Using `test.use()`5const { test } = require('@playwright/test')6test.use({7 login: async ({ page }) => {8 await page.click('text=Log in')9 await page.fill('input[name=email]', '

Full Screen

Playwright tutorial

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.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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