How to use componentB method in ng-mocks

Best JavaScript code snippet using ng-mocks

recognize.spec.ts

Source:recognize.spec.ts Github

copy

Full Screen

1/**2 * @license3 * Copyright Google Inc. All Rights Reserved.4 *5 * Use of this source code is governed by an MIT-style license that can be6 * found in the LICENSE file at https://angular.io/license7 */8import {Routes} from '../src/config';9import {recognize} from '../src/recognize';10import {ActivatedRouteSnapshot, RouterStateSnapshot} from '../src/router_state';11import {PRIMARY_OUTLET, Params} from '../src/shared';12import {DefaultUrlSerializer, UrlTree} from '../src/url_tree';13describe('recognize', () => {14 it('should work', () => {15 checkRecognize([{path: 'a', component: ComponentA}], 'a', (s: RouterStateSnapshot) => {16 checkActivatedRoute(s.root, '', {}, RootComponent);17 checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);18 });19 });20 it('should freeze params object', () => {21 checkRecognize([{path: 'a/:id', component: ComponentA}], 'a/10', (s: RouterStateSnapshot) => {22 checkActivatedRoute(s.root, '', {}, RootComponent);23 const child = s.firstChild(s.root) !;24 expect(Object.isFrozen(child.params)).toBeTruthy();25 });26 });27 it('should support secondary routes', () => {28 checkRecognize(29 [30 {path: 'a', component: ComponentA}, {path: 'b', component: ComponentB, outlet: 'left'},31 {path: 'c', component: ComponentC, outlet: 'right'}32 ],33 'a(left:b//right:c)', (s: RouterStateSnapshot) => {34 const c = s.children(s.root);35 checkActivatedRoute(c[0], 'a', {}, ComponentA);36 checkActivatedRoute(c[1], 'b', {}, ComponentB, 'left');37 checkActivatedRoute(c[2], 'c', {}, ComponentC, 'right');38 });39 });40 it('should set url segment and index properly', () => {41 const url = tree('a(left:b//right:c)');42 recognize(43 RootComponent,44 [45 {path: 'a', component: ComponentA}, {path: 'b', component: ComponentB, outlet: 'left'},46 {path: 'c', component: ComponentC, outlet: 'right'}47 ],48 url, 'a(left:b//right:c)')49 .subscribe((s) => {50 expect(s.root._urlSegment).toBe(url.root);51 expect(s.root._lastPathIndex).toBe(-1);52 const c = s.children(s.root);53 expect(c[0]._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);54 expect(c[0]._lastPathIndex).toBe(0);55 expect(c[1]._urlSegment).toBe(url.root.children['left']);56 expect(c[1]._lastPathIndex).toBe(0);57 expect(c[2]._urlSegment).toBe(url.root.children['right']);58 expect(c[2]._lastPathIndex).toBe(0);59 });60 });61 it('should set url segment and index properly (nested case)', () => {62 const url = tree('a/b/c');63 recognize(64 RootComponent,65 [66 {path: 'a/b', component: ComponentA, children: [{path: 'c', component: ComponentC}]},67 ],68 url, 'a/b/c')69 .subscribe((s: RouterStateSnapshot) => {70 expect(s.root._urlSegment).toBe(url.root);71 expect(s.root._lastPathIndex).toBe(-1);72 const compA = s.firstChild(s.root) !;73 expect(compA._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);74 expect(compA._lastPathIndex).toBe(1);75 const compC = s.firstChild(<any>compA) !;76 expect(compC._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);77 expect(compC._lastPathIndex).toBe(2);78 });79 });80 it('should set url segment and index properly (wildcard)', () => {81 const url = tree('a/b/c');82 recognize(83 RootComponent,84 [85 {path: 'a', component: ComponentA, children: [{path: '**', component: ComponentB}]},86 ],87 url, 'a/b/c')88 .subscribe((s: RouterStateSnapshot) => {89 expect(s.root._urlSegment).toBe(url.root);90 expect(s.root._lastPathIndex).toBe(-1);91 const compA = s.firstChild(s.root) !;92 expect(compA._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);93 expect(compA._lastPathIndex).toBe(0);94 const compC = s.firstChild(<any>compA) !;95 expect(compC._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);96 expect(compC._lastPathIndex).toBe(2);97 });98 });99 it('should match routes in the depth first order', () => {100 checkRecognize(101 [102 {path: 'a', component: ComponentA, children: [{path: ':id', component: ComponentB}]},103 {path: 'a/:id', component: ComponentC}104 ],105 'a/paramA', (s: RouterStateSnapshot) => {106 checkActivatedRoute(s.root, '', {}, RootComponent);107 checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);108 checkActivatedRoute(109 s.firstChild(<any>s.firstChild(s.root)) !, 'paramA', {id: 'paramA'}, ComponentB);110 });111 checkRecognize(112 [{path: 'a', component: ComponentA}, {path: 'a/:id', component: ComponentC}], 'a/paramA',113 (s: RouterStateSnapshot) => {114 checkActivatedRoute(s.root, '', {}, RootComponent);115 checkActivatedRoute(s.firstChild(s.root) !, 'a/paramA', {id: 'paramA'}, ComponentC);116 });117 });118 it('should use outlet name when matching secondary routes', () => {119 checkRecognize(120 [121 {path: 'a', component: ComponentA}, {path: 'b', component: ComponentB, outlet: 'left'},122 {path: 'b', component: ComponentC, outlet: 'right'}123 ],124 'a(right:b)', (s: RouterStateSnapshot) => {125 const c = s.children(s.root);126 checkActivatedRoute(c[0], 'a', {}, ComponentA);127 checkActivatedRoute(c[1], 'b', {}, ComponentC, 'right');128 });129 });130 it('should handle non top-level secondary routes', () => {131 checkRecognize(132 [133 {134 path: 'a',135 component: ComponentA,136 children: [137 {path: 'b', component: ComponentB},138 {path: 'c', component: ComponentC, outlet: 'left'}139 ]140 },141 ],142 'a/(b//left:c)', (s: RouterStateSnapshot) => {143 const c = s.children(<any>s.firstChild(s.root));144 checkActivatedRoute(c[0], 'b', {}, ComponentB, PRIMARY_OUTLET);145 checkActivatedRoute(c[1], 'c', {}, ComponentC, 'left');146 });147 });148 it('should sort routes by outlet name', () => {149 checkRecognize(150 [151 {path: 'a', component: ComponentA}, {path: 'c', component: ComponentC, outlet: 'c'},152 {path: 'b', component: ComponentB, outlet: 'b'}153 ],154 'a(c:c//b:b)', (s: RouterStateSnapshot) => {155 const c = s.children(s.root);156 checkActivatedRoute(c[0], 'a', {}, ComponentA);157 checkActivatedRoute(c[1], 'b', {}, ComponentB, 'b');158 checkActivatedRoute(c[2], 'c', {}, ComponentC, 'c');159 });160 });161 it('should support matrix parameters', () => {162 checkRecognize(163 [164 {path: 'a', component: ComponentA, children: [{path: 'b', component: ComponentB}]},165 {path: 'c', component: ComponentC, outlet: 'left'}166 ],167 'a;a1=11;a2=22/b;b1=111;b2=222(left:c;c1=1111;c2=2222)', (s: RouterStateSnapshot) => {168 const c = s.children(s.root);169 checkActivatedRoute(c[0], 'a', {a1: '11', a2: '22'}, ComponentA);170 checkActivatedRoute(s.firstChild(<any>c[0]) !, 'b', {b1: '111', b2: '222'}, ComponentB);171 checkActivatedRoute(c[1], 'c', {c1: '1111', c2: '2222'}, ComponentC, 'left');172 });173 });174 describe('data', () => {175 it('should set static data', () => {176 checkRecognize(177 [{path: 'a', data: {one: 1}, component: ComponentA}], 'a', (s: RouterStateSnapshot) => {178 const r: ActivatedRouteSnapshot = s.firstChild(s.root) !;179 expect(r.data).toEqual({one: 1});180 });181 });182 it('should merge componentless route\'s data', () => {183 checkRecognize(184 [{185 path: 'a',186 data: {one: 1},187 children: [{path: 'b', data: {two: 2}, component: ComponentB}]188 }],189 'a/b', (s: RouterStateSnapshot) => {190 const r: ActivatedRouteSnapshot = s.firstChild(<any>s.firstChild(s.root)) !;191 expect(r.data).toEqual({one: 1, two: 2});192 });193 });194 it('should set resolved data', () => {195 checkRecognize(196 [{path: 'a', resolve: {one: 'some-token'}, component: ComponentA}], 'a',197 (s: RouterStateSnapshot) => {198 const r: ActivatedRouteSnapshot = s.firstChild(s.root) !;199 expect(r._resolve).toEqual({one: 'some-token'});200 });201 });202 });203 describe('empty path', () => {204 describe('root', () => {205 it('should work', () => {206 checkRecognize([{path: '', component: ComponentA}], '', (s: RouterStateSnapshot) => {207 checkActivatedRoute(s.firstChild(s.root) !, '', {}, ComponentA);208 });209 });210 it('should match when terminal', () => {211 checkRecognize(212 [{path: '', pathMatch: 'full', component: ComponentA}], '',213 (s: RouterStateSnapshot) => {214 checkActivatedRoute(s.firstChild(s.root) !, '', {}, ComponentA);215 });216 });217 it('should work (nested case)', () => {218 checkRecognize(219 [{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}], '',220 (s: RouterStateSnapshot) => {221 checkActivatedRoute(s.firstChild(s.root) !, '', {}, ComponentA);222 checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)) !, '', {}, ComponentB);223 });224 });225 it('should set url segment and index properly', () => {226 const url = tree('');227 recognize(228 RootComponent,229 [{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}], url,230 '')231 .forEach((s: RouterStateSnapshot) => {232 expect(s.root._urlSegment).toBe(url.root);233 expect(s.root._lastPathIndex).toBe(-1);234 const c = s.firstChild(s.root) !;235 expect(c._urlSegment).toBe(url.root);236 expect(c._lastPathIndex).toBe(-1);237 const c2 = s.firstChild(<any>s.firstChild(s.root)) !;238 expect(c2._urlSegment).toBe(url.root);239 expect(c2._lastPathIndex).toBe(-1);240 });241 });242 it('should inherit params', () => {243 checkRecognize(244 [{245 path: 'a',246 component: ComponentA,247 children: [248 {path: '', component: ComponentB, children: [{path: '', component: ComponentC}]}249 ]250 }],251 '/a;p=1', (s: RouterStateSnapshot) => {252 checkActivatedRoute(s.firstChild(s.root) !, 'a', {p: '1'}, ComponentA);253 checkActivatedRoute(s.firstChild(s.firstChild(s.root) !) !, '', {p: '1'}, ComponentB);254 checkActivatedRoute(255 s.firstChild(s.firstChild(s.firstChild(s.root) !) !) !, '', {p: '1'}, ComponentC);256 });257 });258 });259 describe('aux split is in the middle', () => {260 it('should match (non-terminal)', () => {261 checkRecognize(262 [{263 path: 'a',264 component: ComponentA,265 children: [266 {path: 'b', component: ComponentB},267 {path: '', component: ComponentC, outlet: 'aux'}268 ]269 }],270 'a/b', (s: RouterStateSnapshot) => {271 checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);272 const c = s.children(s.firstChild(s.root) !);273 checkActivatedRoute(c[0], 'b', {}, ComponentB);274 checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');275 });276 });277 it('should match (non-termianl) when both primary and secondary and primary has a child',278 () => {279 const config = [{280 path: 'parent',281 children: [282 {283 path: '',284 component: ComponentA,285 children: [286 {path: 'b', component: ComponentB},287 {path: 'c', component: ComponentC},288 ]289 },290 {291 path: '',292 component: ComponentD,293 outlet: 'secondary',294 }295 ]296 }];297 checkRecognize(config, 'parent/b', (s: RouterStateSnapshot) => {298 checkActivatedRoute(s.root, '', {}, RootComponent);299 checkActivatedRoute(s.firstChild(s.root) !, 'parent', {}, undefined !);300 const cc = s.children(s.firstChild(s.root) !);301 checkActivatedRoute(cc[0], '', {}, ComponentA);302 checkActivatedRoute(cc[1], '', {}, ComponentD, 'secondary');303 checkActivatedRoute(s.firstChild(cc[0]) !, 'b', {}, ComponentB);304 });305 });306 it('should match (terminal)', () => {307 checkRecognize(308 [{309 path: 'a',310 component: ComponentA,311 children: [312 {path: 'b', component: ComponentB},313 {path: '', pathMatch: 'full', component: ComponentC, outlet: 'aux'}314 ]315 }],316 'a/b', (s: RouterStateSnapshot) => {317 checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);318 const c = s.children(s.firstChild(s.root) !);319 expect(c.length).toEqual(1);320 checkActivatedRoute(c[0], 'b', {}, ComponentB);321 });322 });323 it('should set url segment and index properly', () => {324 const url = tree('a/b');325 recognize(326 RootComponent, [{327 path: 'a',328 component: ComponentA,329 children: [330 {path: 'b', component: ComponentB},331 {path: '', component: ComponentC, outlet: 'aux'}332 ]333 }],334 url, 'a/b')335 .forEach((s: RouterStateSnapshot) => {336 expect(s.root._urlSegment).toBe(url.root);337 expect(s.root._lastPathIndex).toBe(-1);338 const a = s.firstChild(s.root) !;339 expect(a._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);340 expect(a._lastPathIndex).toBe(0);341 const b = s.firstChild(a) !;342 expect(b._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);343 expect(b._lastPathIndex).toBe(1);344 const c = s.children(a)[1];345 expect(c._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);346 expect(c._lastPathIndex).toBe(0);347 });348 });349 it('should set url segment and index properly when nested empty-path segments', () => {350 const url = tree('a');351 recognize(352 RootComponent, [{353 path: 'a',354 children: [355 {path: '', component: ComponentB, children: [{path: '', component: ComponentC}]}356 ]357 }],358 url, 'a')359 .forEach((s: RouterStateSnapshot) => {360 expect(s.root._urlSegment).toBe(url.root);361 expect(s.root._lastPathIndex).toBe(-1);362 const a = s.firstChild(s.root) !;363 expect(a._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);364 expect(a._lastPathIndex).toBe(0);365 const b = s.firstChild(a) !;366 expect(b._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);367 expect(b._lastPathIndex).toBe(0);368 const c = s.firstChild(b) !;369 expect(c._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);370 expect(c._lastPathIndex).toBe(0);371 });372 });373 it('should set url segment and index properly when nested empty-path segments (2)', () => {374 const url = tree('');375 recognize(376 RootComponent, [{377 path: '',378 children: [379 {path: '', component: ComponentB, children: [{path: '', component: ComponentC}]}380 ]381 }],382 url, '')383 .forEach((s: RouterStateSnapshot) => {384 expect(s.root._urlSegment).toBe(url.root);385 expect(s.root._lastPathIndex).toBe(-1);386 const a = s.firstChild(s.root) !;387 expect(a._urlSegment).toBe(url.root);388 expect(a._lastPathIndex).toBe(-1);389 const b = s.firstChild(a) !;390 expect(b._urlSegment).toBe(url.root);391 expect(b._lastPathIndex).toBe(-1);392 const c = s.firstChild(b) !;393 expect(c._urlSegment).toBe(url.root);394 expect(c._lastPathIndex).toBe(-1);395 });396 });397 });398 describe('aux split at the end (no right child)', () => {399 it('should match (non-terminal)', () => {400 checkRecognize(401 [{402 path: 'a',403 component: ComponentA,404 children: [405 {path: '', component: ComponentB},406 {path: '', component: ComponentC, outlet: 'aux'},407 ]408 }],409 'a', (s: RouterStateSnapshot) => {410 checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);411 const c = s.children(s.firstChild(s.root) !);412 checkActivatedRoute(c[0], '', {}, ComponentB);413 checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');414 });415 });416 it('should match (terminal)', () => {417 checkRecognize(418 [{419 path: 'a',420 component: ComponentA,421 children: [422 {path: '', pathMatch: 'full', component: ComponentB},423 {path: '', pathMatch: 'full', component: ComponentC, outlet: 'aux'},424 ]425 }],426 'a', (s: RouterStateSnapshot) => {427 checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);428 const c = s.children(s.firstChild(s.root) !);429 checkActivatedRoute(c[0], '', {}, ComponentB);430 checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');431 });432 });433 it('should work only only primary outlet', () => {434 checkRecognize(435 [{436 path: 'a',437 component: ComponentA,438 children: [439 {path: '', component: ComponentB},440 {path: 'c', component: ComponentC, outlet: 'aux'},441 ]442 }],443 'a/(aux:c)', (s: RouterStateSnapshot) => {444 checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);445 const c = s.children(s.firstChild(s.root) !);446 checkActivatedRoute(c[0], '', {}, ComponentB);447 checkActivatedRoute(c[1], 'c', {}, ComponentC, 'aux');448 });449 });450 it('should work when split is at the root level', () => {451 checkRecognize(452 [453 {path: '', component: ComponentA}, {path: 'b', component: ComponentB},454 {path: 'c', component: ComponentC, outlet: 'aux'}455 ],456 '(aux:c)', (s: RouterStateSnapshot) => {457 checkActivatedRoute(s.root, '', {}, RootComponent);458 const children = s.children(s.root);459 expect(children.length).toEqual(2);460 checkActivatedRoute(children[0], '', {}, ComponentA);461 checkActivatedRoute(children[1], 'c', {}, ComponentC, 'aux');462 });463 });464 });465 describe('split at the end (right child)', () => {466 it('should match (non-terminal)', () => {467 checkRecognize(468 [{469 path: 'a',470 component: ComponentA,471 children: [472 {path: '', component: ComponentB, children: [{path: 'd', component: ComponentD}]},473 {474 path: '',475 component: ComponentC,476 outlet: 'aux',477 children: [{path: 'e', component: ComponentE}]478 },479 ]480 }],481 'a/(d//aux:e)', (s: RouterStateSnapshot) => {482 checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);483 const c = s.children(s.firstChild(s.root) !);484 checkActivatedRoute(c[0], '', {}, ComponentB);485 checkActivatedRoute(s.firstChild(c[0]) !, 'd', {}, ComponentD);486 checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');487 checkActivatedRoute(s.firstChild(c[1]) !, 'e', {}, ComponentE);488 });489 });490 });491 });492 describe('wildcards', () => {493 it('should support simple wildcards', () => {494 checkRecognize(495 [{path: '**', component: ComponentA}], 'a/b/c/d;a1=11', (s: RouterStateSnapshot) => {496 checkActivatedRoute(s.firstChild(s.root) !, 'a/b/c/d', {a1: '11'}, ComponentA);497 });498 });499 });500 describe('componentless routes', () => {501 it('should work', () => {502 checkRecognize(503 [{504 path: 'p/:id',505 children: [506 {path: 'a', component: ComponentA},507 {path: 'b', component: ComponentB, outlet: 'aux'}508 ]509 }],510 'p/11;pp=22/(a;pa=33//aux:b;pb=44)', (s: RouterStateSnapshot) => {511 const p = s.firstChild(s.root) !;512 checkActivatedRoute(p, 'p/11', {id: '11', pp: '22'}, undefined !);513 const c = s.children(p);514 checkActivatedRoute(c[0], 'a', {id: '11', pp: '22', pa: '33'}, ComponentA);515 checkActivatedRoute(c[1], 'b', {id: '11', pp: '22', pb: '44'}, ComponentB, 'aux');516 });517 });518 it('should merge params until encounters a normal route', () => {519 checkRecognize(520 [{521 path: 'p/:id',522 children: [{523 path: 'a/:name',524 children: [{525 path: 'b',526 component: ComponentB,527 children: [{path: 'c', component: ComponentC}]528 }]529 }]530 }],531 'p/11/a/victor/b/c', (s: RouterStateSnapshot) => {532 const p = s.firstChild(s.root) !;533 checkActivatedRoute(p, 'p/11', {id: '11'}, undefined !);534 const a = s.firstChild(p) !;535 checkActivatedRoute(a, 'a/victor', {id: '11', name: 'victor'}, undefined !);536 const b = s.firstChild(a) !;537 checkActivatedRoute(b, 'b', {id: '11', name: 'victor'}, ComponentB);538 const c = s.firstChild(b) !;539 checkActivatedRoute(c, 'c', {}, ComponentC);540 });541 });542 });543 describe('empty URL leftovers', () => {544 it('should not throw when no children matching', () => {545 checkRecognize(546 [{path: 'a', component: ComponentA, children: [{path: 'b', component: ComponentB}]}],547 '/a', (s: RouterStateSnapshot) => {548 const a = s.firstChild(s.root);549 checkActivatedRoute(a !, 'a', {}, ComponentA);550 });551 });552 it('should not throw when no children matching (aux routes)', () => {553 checkRecognize(554 [{555 path: 'a',556 component: ComponentA,557 children: [558 {path: 'b', component: ComponentB},559 {path: '', component: ComponentC, outlet: 'aux'},560 ]561 }],562 '/a', (s: RouterStateSnapshot) => {563 const a = s.firstChild(s.root) !;564 checkActivatedRoute(a, 'a', {}, ComponentA);565 checkActivatedRoute(a.children[0], '', {}, ComponentC, 'aux');566 });567 });568 });569 describe('custom path matchers', () => {570 it('should use custom path matcher', () => {571 const matcher = (s: any, g: any, r: any) => {572 if (s[0].path === 'a') {573 return {consumed: s.slice(0, 2), posParams: {id: s[1]}};574 } else {575 return null;576 }577 };578 checkRecognize(579 [{580 matcher: matcher,581 component: ComponentA,582 children: [{path: 'b', component: ComponentB}]583 }] as any,584 '/a/1;p=99/b', (s: RouterStateSnapshot) => {585 const a = s.root.firstChild !;586 checkActivatedRoute(a, 'a/1', {id: '1', p: '99'}, ComponentA);587 checkActivatedRoute(a.firstChild !, 'b', {}, ComponentB);588 });589 });590 });591 describe('query parameters', () => {592 it('should support query params', () => {593 const config = [{path: 'a', component: ComponentA}];594 checkRecognize(config, 'a?q=11', (s: RouterStateSnapshot) => {595 expect(s.root.queryParams).toEqual({q: '11'});596 expect(s.root.queryParamMap.get('q')).toEqual('11');597 });598 });599 it('should freeze query params object', () => {600 checkRecognize([{path: 'a', component: ComponentA}], 'a?q=11', (s: RouterStateSnapshot) => {601 expect(Object.isFrozen(s.root.queryParams)).toBeTruthy();602 });603 });604 });605 describe('fragment', () => {606 it('should support fragment', () => {607 const config = [{path: 'a', component: ComponentA}];608 checkRecognize(609 config, 'a#f1', (s: RouterStateSnapshot) => { expect(s.root.fragment).toEqual('f1'); });610 });611 });612 describe('error handling', () => {613 it('should error when two routes with the same outlet name got matched', () => {614 recognize(615 RootComponent,616 [617 {path: 'a', component: ComponentA}, {path: 'b', component: ComponentB, outlet: 'aux'},618 {path: 'c', component: ComponentC, outlet: 'aux'}619 ],620 tree('a(aux:b//aux:c)'), 'a(aux:b//aux:c)')621 .subscribe((_) => {}, (s: RouterStateSnapshot) => {622 expect(s.toString())623 .toContain(624 'Two segments cannot have the same outlet name: \'aux:b\' and \'aux:c\'.');625 });626 });627 });628});629function checkRecognize(config: Routes, url: string, callback: any): void {630 recognize(RootComponent, config, tree(url), url).subscribe(callback, e => { throw e; });631}632function checkActivatedRoute(633 actual: ActivatedRouteSnapshot, url: string, params: Params, cmp: Function,634 outlet: string = PRIMARY_OUTLET): void {635 if (actual === null) {636 expect(actual).not.toBeNull();637 } else {638 expect(actual.url.map(s => s.path).join('/')).toEqual(url);639 expect(actual.params).toEqual(params);640 expect(actual.component).toBe(cmp);641 expect(actual.outlet).toEqual(outlet);642 }643}644function tree(url: string): UrlTree {645 return new DefaultUrlSerializer().parse(url);646}647class RootComponent {}648class ComponentA {}649class ComponentB {}650class ComponentC {}651class ComponentD {}...

Full Screen

Full Screen

hash.test.ts

Source:hash.test.ts Github

copy

Full Screen

1import test, { ExecutionContext } from 'ava';2import { Component } from '../../src/types';3import hash from '../../src/utils/hash';4type Context = ExecutionContext<unknown>;5const ComponentA: Component = {6 name: 'Test',7 orientation: 'HORIZONTAL',8 jsx: `() => {9 return <div>Some Component</div>;10 }`,11 styles: `() => {12 return {13 root: {14 backgroundColor: 'red',15 },16 };17 }`,18 type: 'COLUMN',19 allowedTypes: [],20 styleType: '',21};22const foo = {23 bar: 'baz',24};25test('generate hash from object should be the same every time', (t: Context): void => {26 t.is(hash(ComponentA), hash(ComponentA));27 t.is(hash(foo), hash(foo));28});29test('generate hash from a component with a different name should return different hash', (t: Context): void => {30 let ComponentB = { ...ComponentA };31 ComponentB.name = 'test';32 t.not(hash(ComponentA), hash(ComponentB));33});34test('generate hash from a component with a different orientation should return a different hash', (t: Context): void => {35 let ComponentB = { ...ComponentA };36 ComponentB.orientation = 'VERTICAL';37 t.not(hash(ComponentA), hash(ComponentB));38});39test('generate hash from a component with a different jsx should return different hash', (t: Context): void => {40 let ComponentB = { ...ComponentA };41 ComponentB.jsx = `() => {42 return <span>Some Component</span>;43 }`;44 t.not(hash(ComponentA), hash(ComponentB));45});46test('generate hash from a component with a different styles should return different hash', (t: Context): void => {47 let ComponentB = { ...ComponentA };48 ComponentB.styles = `() => {49 return {50 root: {51 backgroundColor: 'green',52 },53 };54 }`;55 t.not(hash(ComponentA), hash(ComponentB));56});57test('generate hash from a component with a different type should return a different hash', (t: Context): void => {58 let ComponentB = { ...ComponentA };59 ComponentB.type = 'ROW';60 t.not(hash(ComponentA), hash(ComponentB));61});62test('generate hash from a component with a different allowed types should return a different hash', (t: Context): void => {63 let ComponentB = { ...ComponentA };64 ComponentB.allowedTypes = ['COLUMN', 'ROW'];65 t.not(hash(ComponentA), hash(ComponentB));...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MockBuilder, MockRender } from 'ng-mocks';2import { ComponentB } from './componentB';3import { ComponentA } from './componentA';4describe('ComponentA', () => {5 beforeEach(() => MockBuilder(ComponentA).mock(ComponentB));6 it('should create', () => {7 const fixture = MockRender(ComponentA);8 expect(fixture.point.componentInstance).toBeDefined();9 });10});11import { Component } from '@angular/core';12import { ComponentB } from './componentB';13@Component({14})15export class ComponentA {16 constructor(private componentB: ComponentB) {}17}18import { Component } from '@angular/core';19@Component({20})21export class ComponentB {}22import { MockBuilder, MockRender } from 'ng-mocks';23import { ServiceB } from './serviceB';24import { ComponentA } from './componentA';25describe('ComponentA', () => {26 beforeEach(() => MockBuilder(ComponentA).mock(ServiceB));27 it('should create', () => {28 const fixture = MockRender(ComponentA);29 expect(fixture.point.componentInstance).toBeDefined();30 });31});32import { Component } from '@angular/core';33import { ServiceB } from './serviceB';34@Component({

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MockBuilder, MockRender } from 'ng-mocks';2import { ComponentB } from 'componentB';3import { ComponentA } from './componentA';4describe('ComponentA', () => {5 beforeEach(() => MockBuilder(ComponentA).mock(ComponentB));6 it('should create', () => {7 const fixture = MockRender(ComponentA);8 expect(fixture.point.componentInstance).toBeTruthy();9 });10});11import { Component } from '@angular/core';12import { ComponentB } from 'componentB';13@Component({14})15export class ComponentA {16 constructor(public componentB: ComponentB) {}17}18import { Component } from '@angular/core';19@Component({20})21export class ComponentB {}22import { MockBuilder, MockRender } from 'ng-mocks';23import { ComponentB } from './componentB';24import { ComponentA } from 'componentA';25describe('ComponentB', () => {26 beforeEach(() => MockBuilder(ComponentB));27 it('should create', () => {28 const fixture = MockRender(ComponentA);29 expect(fixture.point.componentInstance).toBeTruthy();30 });31});

Full Screen

Using AI Code Generation

copy

Full Screen

1import {ComponentB} from 'ng-mocks';2ComponentB.method();3import {ComponentA} from 'ng-mocks';4ComponentA.method();5import {ComponentC} from 'ng-mocks';6ComponentC.method();7import {ComponentD} from 'ng-mocks';8ComponentD.method();9import {ComponentE} from 'ng-mocks';10ComponentE.method();11import {ComponentF} from 'ng-mocks';12ComponentF.method();13import {ComponentG} from 'ng-mocks';14ComponentG.method();15import {ComponentH} from 'ng-mocks';16ComponentH.method();17import {ComponentI} from 'ng-mocks';18ComponentI.method();19import {ComponentJ} from 'ng-mocks';20ComponentJ.method();21import {ComponentK} from 'ng-mocks';22ComponentK.method();23import {ComponentL} from 'ng-mocks';24ComponentL.method();25import {ComponentM} from 'ng-mocks';26ComponentM.method();27import {ComponentN} from 'ng-mocks';28ComponentN.method();29import {ComponentO} from 'ng-mocks';30ComponentO.method();31import {ComponentP} from 'ng-mocks';32ComponentP.method();33import {ComponentQ} from 'ng-mocks';34ComponentQ.method();35import {ComponentR} from 'ng-mocks';36ComponentR.method();37import {ComponentS} from 'ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';2import { ComponentB } from './componentB';3import { ComponentA } from './componentA';4import { ComponentAComponent } from './componentA.component';5import { ComponentBComponent } from './componentB.component';6describe('ComponentA', () => {7 beforeEach(() => MockBuilder(ComponentAComponent));8 beforeEach(() => MockRender(ComponentAComponent));9 it('should have a componentB', () => {10 const componentB = ngMocks.findInstance(ComponentBComponent);11 const result = componentB.method();12 expect(result).toEqual('componentB');13 });14});15import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';16import { ComponentB } from './componentB';17import { ComponentA } from './componentA';18import { ComponentAComponent } from './componentA.component';19import { ComponentBComponent } from './componentB.component';20describe('ComponentA', () => {21 beforeEach(() => MockBuilder(ComponentAComponent));22 beforeEach(() => MockRender(ComponentAComponent));23 it('should have a componentB', () => {24 const componentB = ngMocks.findInstance(ComponentBComponent);25 const result = componentB.method();26 expect(result).toEqual('componentB');27 });28});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ComponentB } from 'ng-mocks';2import { ComponentA } from 'ng-mocks';3import { ComponentB } from 'ng-mocks';4import { ComponentA } from 'ng-mocks';5import { ComponentB } from 'ng-mocks';6import { ComponentA } from 'ng-mocks';7import { ComponentB } from 'ng-mocks';8import { ComponentA } from 'ng-mocks';9import { ComponentB } from 'ng-mocks';10import { ComponentA } from 'ng-mocks';11import { ComponentB } from 'ng-mocks';12import { ComponentA } from 'ng-mocks';13import { ComponentB } from 'ng-mocks';14import { ComponentA } from 'ng-mocks';15import { ComponentB } from 'ng-mocks';16import { ComponentA } from 'ng-mocks';17import { ComponentB } from 'ng-mocks';18import { ComponentA } from 'ng-mocks';19import { ComponentB } from 'ng-mocks';20import { ComponentA } from 'ng-mocks';21import { ComponentB } from 'ng-mocks';22import { ComponentA } from 'ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MockComponent } from 'ng-mocks';2import { ComponentB } from './componentB';3import { ComponentA } from './componentA';4describe('ComponentA', () => {5 it('should create', () => {6 const component = fixture.componentInstance;7 expect(component).toBeTruthy();8 });9 it('should call componentB method', () => {10 const component = fixture.componentInstance;11 const componentB = MockComponent(ComponentB);12 componentB.method();13 expect(componentB.method).toHaveBeenCalled();14 });15});16import { MockComponent } from 'ng-mocks';17import { ComponentB } from './componentB';18import { ComponentA } from './componentA';19describe('ComponentA', () => {20 it('should create', () => {21 const component = fixture.componentInstance;22 expect(component).toBeTruthy();23 });24 it('should call componentB method', () => {25 const component = fixture.componentInstance;26 const componentB = MockComponent(ComponentB);27 spyOn(componentB, 'method');28 componentB.method();29 expect(componentB.method).toHaveBeenCalled();30 });31});32In this article, we will see how to use the MockPipe() method of ng-mocks to create a mock pipe for testing. The MockPipe() method of ng-mocks is used to create a mock pipe. It takes the pipe class as an argument and returns a mock pipe. It is used to test the component that uses the pipe. We can use the MockPipe() method to create a mock pipe object and then use the spyOn

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run ng-mocks 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