How to use componentA 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 }],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 });597 });598 it('should freeze query params object', () => {599 checkRecognize([{path: 'a', component: ComponentA}], 'a?q=11', (s: RouterStateSnapshot) => {600 expect(Object.isFrozen(s.root.queryParams)).toBeTruthy();601 });602 });603 });604 describe('fragment', () => {605 it('should support fragment', () => {606 const config = [{path: 'a', component: ComponentA}];607 checkRecognize(608 config, 'a#f1', (s: RouterStateSnapshot) => { expect(s.root.fragment).toEqual('f1'); });609 });610 });611 describe('error handling', () => {612 it('should error when two routes with the same outlet name got matched', () => {613 recognize(614 RootComponent,615 [616 {path: 'a', component: ComponentA}, {path: 'b', component: ComponentB, outlet: 'aux'},617 {path: 'c', component: ComponentC, outlet: 'aux'}618 ],619 tree('a(aux:b//aux:c)'), 'a(aux:b//aux:c)')620 .subscribe((_) => {}, (s: RouterStateSnapshot) => {621 expect(s.toString())622 .toContain(623 'Two segments cannot have the same outlet name: \'aux:b\' and \'aux:c\'.');624 });625 });626 });627});628function checkRecognize(config: Routes, url: string, callback: any): void {629 recognize(RootComponent, config, tree(url), url).subscribe(callback, e => { throw e; });630}631function checkActivatedRoute(632 actual: ActivatedRouteSnapshot, url: string, params: Params, cmp: Function,633 outlet: string = PRIMARY_OUTLET): void {634 if (actual === null) {635 expect(actual).not.toBeNull();636 } else {637 expect(actual.url.map(s => s.path).join('/')).toEqual(url);638 expect(actual.params).toEqual(params);639 expect(actual.component).toBe(cmp);640 expect(actual.outlet).toEqual(outlet);641 }642}643function tree(url: string): UrlTree {644 return new DefaultUrlSerializer().parse(url);645}646class RootComponent {}647class ComponentA {}648class ComponentB {}649class ComponentC {}650class ComponentD {}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { componentA } from 'ng-mocks';2import { componentB } from 'ng-mocks';3import { componentC } from 'ng-mocks';4import { componentD } from 'ng-mocks';5import { componentE } from 'ng-mocks';6import { componentF } from 'ng-mocks';7import { componentG } from 'ng-mocks';8import { componentH } from 'ng-mocks';9import { componentI } from 'ng-mocks';10import { componentJ } from 'ng-mocks';11import { componentK } from 'ng-mocks';12import { componentL } from 'ng-mocks';13import { componentM } from 'ng-mocks';14import { componentN } from 'ng-mocks';15import { componentO } from 'ng-mocks';16import { componentP } from 'ng-mocks';17import { componentQ } from 'ng-mocks';18import { componentR } from 'ng-mocks';19import { componentS } from 'ng-mocks';20import { componentT } from 'ng-mocks';21import { componentU } from 'ng-mocks';22import { componentV } from 'ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1import componentAMethod from 'ng-mocks';2import componentBMethod from 'ng-mocks';3import componentAMethod from 'ng-mocks';4import componentBMethod from 'ng-mocks';5import { componentAMethod } from 'ng-mocks';6import { componentBMethod } from 'ng-mocks';7import { componentAMethod } from 'ng-mocks';8import { componentBMethod } from 'ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ComponentA } from 'ng-mocks';2import { ComponentB } from 'ng-mocks';3import { ComponentC } from 'ng-mocks';4import { ComponentD } from 'ng-mocks';5describe('Test', () => {6 it('should test', () => {7 const componentA = ComponentA.get(ComponentB);8 const componentB = ComponentB.get(ComponentC);9 const componentC = ComponentC.get(ComponentD);10 const componentD = ComponentD.get(ComponentA);11 });12});13"devDependencies": {14 }15"paths": {16 }17"paths": {18 }19"paths": {20 }21"architect": {22 "build": {23 "options": {24 "paths": {25 }26I have also tried using the following import statement:27import { ComponentA } from 'ng-mocks/lib/mocks/component/component';28I have also tried using the following import statement:29import { ComponentA } from 'ng-mocks/lib/mocks/component/component';30I have also tried using the following import statement:31import { ComponentA } from 'ng-mocks/lib/mocks/component/component';32I have also tried using the following import statement:

Full Screen

Using AI Code Generation

copy

Full Screen

1const { MockBuilder, MockRender, ngMocks } = require('ng-mocks');2const { ComponentA } = require('componentA');3describe('ComponentA', () => {4 beforeEach(() => MockBuilder(ComponentA));5 it('should have a method', () => {6 const fixture = MockRender(ComponentA);7 const component = ngMocks.findInstance(ComponentA);8 expect(component).toBeDefined();9 expect(component.method()).toBe('something');10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ComponentA } from 'componentA';2import { MockComponentA } from 'ng-mocks';3describe('test', () => {4 it('test', () => {5 const componentA = MockComponentA();6 componentA.method();7 });8});9export class ComponentA {10 method() {11 console.log('method');12 }13}

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2 it('test', () => {3 const fixture = MockRender(`4 `);5 const instance = MockInstance(ComponentAComponent, fixture);6 spyOn(instance, 'method');7 instance.method();8 expect(instance.method).toHaveBeenCalled();9 });10});11describe('test', () => {12 it('test', () => {13 const fixture = MockRender(`14 `);15 const instance = MockInstance(ComponentBComponent, fixture);16 spyOn(instance, 'method');17 instance.method();18 expect(instance.method).toHaveBeenCalled();19 });20});21describe('test', () => {22 it('test', () => {23 const fixture = MockRender(`24 `);25 const instance = fixture.debugElement.query(By.directive(ComponentBComponent)).componentInstance;26 spyOn(instance, 'method');27 instance.method();28 expect(instance.method).toHaveBeenCalled();29 });30});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ComponentA } from 'ng-mocks';2describe('test', () => {3 it('should test', () => {4 ComponentA.method();5 });6});7import { ComponentA } from 'ng-mocks';8describe('test', () => {9 it('should test', () => {10 ComponentA.method();11 });12});13import { ComponentA } from 'ng-mocks';14describe('test', () => {15 it('should test', () => {16 ComponentA.method();17 });18});19import { ComponentA } from 'ng-mocks';20describe('test', () => {21 it('should test', () => {22 ComponentA.method();23 });24});25import { ComponentA } from 'ng-mocks';26describe('test', () => {27 it('should test', () => {28 ComponentA.method();29 });30});31import { ComponentA } from 'ng-mocks';32describe('test', () => {33 it('should test', () => {34 ComponentA.method();35 });36});37import { ComponentA } from 'ng-mocks';38describe('test', () => {39 it('should test', () => {40 ComponentA.method();41 });42});43import { ComponentA } from 'ng-mocks';44describe('test', () => {45 it('should test', () => {46 ComponentA.method();47 });48});49import { ComponentA } from 'ng-mocks';50describe('test', () => {51 it('should test', () => {52 ComponentA.method();53 });54});55import { ComponentA } from 'ng-mocks';56describe('test', () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MockComponent } from 'ng-mocks';2import { ComponentA } from './component-a';3const componentA = MockComponent(ComponentA);4import { MockComponent } from 'ng-mocks';5import { ComponentA } from './component-a';6const componentA = MockComponent(ComponentA);7I have been trying to figure out how to import MockComponent from the ng-mocks library that is installed

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ComponentA } from 'ng-mocks';2import { TestBed } from '@angular/core/testing';3let componentA = ComponentA.create();4let result = componentA.methodA();5console.log(result);6import { ComponentA } from 'ng-mocks';7import { TestBed } from '@angular/core/testing';8describe('test', () => {9 it('should work', () => {10 const componentA = ComponentA.create();11 const result = componentA.methodA();12 expect(result).toBe('A');13 });14});15import { ComponentA } from 'ng-mocks';16import { TestBed } from '@angular/core/testing';17describe('test', () => {18 it('should work', () => {19 const componentA = ComponentA.create();20 const result = componentA.methodA();21 expect(result).toBe('A');22 });23});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Component, OnInit } from '@angular/core';2import { FormControl } from '@angular/forms';3@Component({4})5export class DatePickerComponent implements OnInit {6 date = new FormControl(new Date());7 serializedDate = new FormControl((new Date()).toISOString());8 constructor() { }9 ngOnInit() {10 }11}

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