Best JavaScript code snippet using ng-mocks
di.integration.spec.ts
Source:di.integration.spec.ts
1import { DI, IContainer, inject, InterfaceSymbol, Registration, singleton } from '@aurelia/kernel';2import { assert, createSpy, ISpy } from '@aurelia/testing';3describe('DI.singleton', function () {4 describe('registerInRequester', function () {5 class Foo {6 }7 const fooSelfRegister = DI.singleton(Foo, { scoped: true });8 it('root', function () {9 const root = DI.createContainer();10 const foo1 = root.get(fooSelfRegister);11 const foo2 = root.get(fooSelfRegister);12 assert.strictEqual(foo1, foo2);13 });14 it('children', function () {15 const root = DI.createContainer();16 const child1 = root.createChild();17 const child2 = root.createChild();18 const foo1 = child1.get(fooSelfRegister);19 const foo2 = child2.get(fooSelfRegister);20 assert.notStrictEqual(foo1, foo2);21 });22 });23});24describe('DI.getDependencies', function () {25 it('string param', function () {26 @singleton27 class Foo {28 public constructor(public readonly test: string) {}29 }30 const actual = DI.getDependencies(Foo);31 assert.deepStrictEqual(actual, [String]);32 });33 it('class param', function () {34 class Bar {}35 @singleton36 class Foo {37 public constructor(public readonly test: Bar) {}38 }39 const actual = DI.getDependencies(Foo);40 assert.deepStrictEqual(actual, [Bar]);41 });42});43describe('DI.createInterface() -> container.get()', function () {44 let container: IContainer;45 interface ITransient {}46 class Transient implements ITransient {}47 let ITransient: InterfaceSymbol<ITransient>;48 interface ISingleton {}49 class Singleton implements ISingleton {}50 let ISingleton: InterfaceSymbol<ISingleton>;51 interface IInstance {}52 class Instance implements IInstance {}53 let IInstance: InterfaceSymbol<IInstance>;54 let instance: Instance;55 interface ICallback {}56 class Callback implements ICallback {}57 let ICallback: InterfaceSymbol<ICallback>;58 interface ICachedCallback {}59 class CachedCallback implements ICachedCallback {}60 let ICachedCallback: InterfaceSymbol<ICachedCallback>;61 const cachedCallback = 'cachedCallBack';62 let callbackCount = 0;63 function callbackToCache() {64 ++callbackCount;65 return new CachedCallback();66 }67 let callback: ISpy<() => ICallback>;68 let get: ISpy<IContainer['get']>;69 // eslint-disable-next-line mocha/no-hooks70 beforeEach(function () {71 callbackCount = 0;72 container = DI.createContainer();73 ITransient = DI.createInterface<ITransient>('ITransient', x => x.transient(Transient));74 ISingleton = DI.createInterface<ISingleton>('ISingleton', x => x.singleton(Singleton));75 instance = new Instance();76 IInstance = DI.createInterface<IInstance>('IInstance', x => x.instance(instance));77 callback = createSpy(() => new Callback());78 ICallback = DI.createInterface<ICallback>('ICallback', x => x.callback(callback));79 ICachedCallback = DI.createInterface<ICachedCallback>('ICachedCallback', x => x.cachedCallback(callbackToCache));80 get = createSpy(container, 'get', true);81 });82 // eslint-disable-next-line mocha/no-hooks83 afterEach(function () {84 get.restore();85 });86 describe('leaf', function () {87 it(`transient registration returns a new instance each time`, function () {88 const actual1 = container.get(ITransient);89 assert.instanceOf(actual1, Transient, `actual1`);90 const actual2 = container.get(ITransient);91 assert.instanceOf(actual2, Transient, `actual2`);92 assert.notStrictEqual(actual1, actual2, `actual1`);93 assert.deepStrictEqual(94 get.calls,95 [96 [ITransient],97 [ITransient],98 ],99 `get.calls`,100 );101 });102 it(`singleton registration returns the same instance each time`, function () {103 const actual1 = container.get(ISingleton);104 assert.instanceOf(actual1, Singleton, `actual1`);105 const actual2 = container.get(ISingleton);106 assert.instanceOf(actual2, Singleton, `actual2`);107 assert.strictEqual(actual1, actual2, `actual1`);108 assert.deepStrictEqual(109 get.calls,110 [111 [ISingleton],112 [ISingleton],113 ],114 `get.calls`,115 );116 });117 it(`instance registration returns the same instance each time`, function () {118 const actual1 = container.get(IInstance);119 assert.instanceOf(actual1, Instance, `actual1`);120 const actual2 = container.get(IInstance);121 assert.instanceOf(actual2, Instance, `actual2`);122 assert.strictEqual(actual1, instance, `actual1`);123 assert.strictEqual(actual2, instance, `actual2`);124 assert.deepStrictEqual(125 get.calls,126 [127 [IInstance],128 [IInstance],129 ],130 `get.calls`,131 );132 });133 it(`callback registration is invoked each time`, function () {134 const actual1 = container.get(ICallback);135 assert.instanceOf(actual1, Callback, `actual1`);136 const actual2 = container.get(ICallback);137 assert.instanceOf(actual2, Callback, `actual2`);138 assert.notStrictEqual(actual1, actual2, `actual1`);139 assert.deepStrictEqual(140 callback.calls,141 [142 [container, container, container.getResolver(ICallback)],143 [container, container, container.getResolver(ICallback)],144 ],145 `callback.calls`,146 );147 assert.deepStrictEqual(148 get.calls,149 [150 [ICallback],151 [ICallback],152 ],153 `get.calls`,154 );155 });156 it(`cachedCallback registration is invoked once`, function () {157 container.register(Registration.cachedCallback(cachedCallback, callbackToCache));158 const child = container.createChild();159 child.register(Registration.cachedCallback(cachedCallback, callbackToCache));160 const actual1 = container.get(cachedCallback);161 const actual2 = container.get(cachedCallback);162 assert.strictEqual(callbackCount, 1, `only called once`);163 assert.strictEqual(actual2, actual1, `getting from the same container`);164 const actual3 = child.get(cachedCallback);165 assert.notStrictEqual(actual3, actual1, `get from child that has new resolver`);166 });167 it(`cacheCallback multiple root containers`, function () {168 const container0 = DI.createContainer();169 const container1 = DI.createContainer();170 container0.register(Registration.cachedCallback(cachedCallback, callbackToCache));171 container1.register(Registration.cachedCallback(cachedCallback, callbackToCache));172 const actual11 = container0.get(cachedCallback);173 const actual12 = container0.get(cachedCallback);174 assert.strictEqual(callbackCount, 1, 'one callback');175 assert.strictEqual(actual11, actual12);176 const actual21 = container1.get(cachedCallback);177 const actual22 = container1.get(cachedCallback);178 assert.strictEqual(callbackCount, 2);179 assert.strictEqual(actual21, actual22);180 });181 it(`cacheCallback different containers should not create the same singleton GH #1064`, function () {182 const reg = Registration.cachedCallback(cachedCallback, callbackToCache);183 const container0 = DI.createContainer();184 const container1 = DI.createContainer();185 container0.register(reg);186 container1.register(reg);187 const actual11 = container0.get(cachedCallback);188 const actual12 = container0.get(cachedCallback);189 assert.strictEqual(actual11, actual12, "11 equals 12");190 assert.strictEqual(callbackCount, 1, "callback count 1");191 const actual21 = container1.get(cachedCallback);192 const actual22 = container1.get(cachedCallback);193 assert.strictEqual(actual21, actual22, "21 equals 22");194 assert.strictEqual(callbackCount, 2, "callback count 2");195 assert.notStrictEqual(actual11, actual21, "11 does not equal 21");196 });197 it(`cachedCallback registration on interface is invoked once`, function () {198 const actual1 = container.get(ICachedCallback);199 const actual2 = container.get(ICachedCallback);200 assert.strictEqual(callbackCount, 1, `only called once`);201 assert.strictEqual(actual2, actual1, `getting from the same container`);202 });203 it(`cacheCallback interface multiple root containers`, function () {204 const container0 = DI.createContainer();205 const container1 = DI.createContainer();206 const actual11 = container0.get(ICachedCallback);207 const actual12 = container0.get(ICachedCallback);208 assert.strictEqual(callbackCount, 1);209 assert.strictEqual(actual11, actual12);210 const actual21 = container1.get(ICachedCallback);211 const actual22 = container1.get(ICachedCallback);212 assert.strictEqual(callbackCount, 2);213 assert.strictEqual(actual21, actual22);214 });215 it(`InterfaceSymbol alias to transient registration returns a new instance each time`, function () {216 interface IAlias {}217 const IAlias = DI.createInterface<IAlias>('IAlias', x => x.aliasTo(ITransient));218 const actual1 = container.get(IAlias);219 assert.instanceOf(actual1, Transient, `actual1`);220 const actual2 = container.get(IAlias);221 assert.instanceOf(actual2, Transient, `actual2`);222 assert.notStrictEqual(actual1, actual2, `actual1`);223 assert.deepStrictEqual(224 get.calls,225 [226 [IAlias],227 [ITransient],228 [IAlias],229 [ITransient],230 ],231 `get.calls`,232 );233 });234 it(`InterfaceSymbol alias to singleton registration returns the same instance each time`, function () {235 interface IAlias {}236 const IAlias = DI.createInterface<IAlias>('IAlias', x => x.aliasTo(ISingleton));237 const actual1 = container.get(IAlias);238 assert.instanceOf(actual1, Singleton, `actual1`);239 const actual2 = container.get(IAlias);240 assert.instanceOf(actual2, Singleton, `actual2`);241 assert.strictEqual(actual1, actual2, `actual1`);242 assert.deepStrictEqual(243 get.calls,244 [245 [IAlias],246 [ISingleton],247 [IAlias],248 [ISingleton],249 ],250 `get.calls`,251 );252 });253 it(`InterfaceSymbol alias to instance registration returns the same instance each time`, function () {254 interface IAlias {}255 const IAlias = DI.createInterface<IAlias>('IAlias', x => x.aliasTo(IInstance));256 const actual1 = container.get(IAlias);257 assert.instanceOf(actual1, Instance, `actual1`);258 const actual2 = container.get(IAlias);259 assert.instanceOf(actual2, Instance, `actual2`);260 assert.strictEqual(actual1, instance, `actual1`);261 assert.strictEqual(actual2, instance, `actual2`);262 assert.deepStrictEqual(263 get.calls,264 [265 [IAlias],266 [IInstance],267 [IAlias],268 [IInstance],269 ],270 `get.calls`,271 );272 });273 // TODO: make test work274 it(`InterfaceSymbol alias to callback registration is invoked each time`, function () {275 interface IAlias {}276 const IAlias = DI.createInterface<IAlias>('IAlias', x => x.aliasTo(ICallback));277 const actual1 = container.get(IAlias);278 assert.instanceOf(actual1, Callback, `actual1`);279 const actual2 = container.get(IAlias);280 assert.instanceOf(actual2, Callback, `actual2`);281 assert.notStrictEqual(actual1, actual2, `actual1`);282 assert.deepStrictEqual(283 callback.calls,284 [285 [container, container, container.getResolver(ICallback)],286 [container, container, container.getResolver(ICallback)],287 ],288 `callback.calls`,289 );290 assert.deepStrictEqual(291 get.calls,292 [293 [IAlias],294 [ICallback],295 [IAlias],296 [ICallback],297 ],298 `get.calls`,299 );300 });301 it(`string alias to transient registration returns a new instance each time`, function () {302 container.register(Registration.aliasTo(ITransient, 'alias'));303 const actual1 = container.get('alias');304 assert.instanceOf(actual1, Transient, `actual1`);305 const actual2 = container.get('alias');306 assert.instanceOf(actual2, Transient, `actual2`);307 assert.notStrictEqual(actual1, actual2, `actual1`);308 assert.deepStrictEqual(309 get.calls,310 [311 ['alias'],312 [ITransient],313 ['alias'],314 [ITransient],315 ],316 `get.calls`,317 );318 });319 it(`string alias to singleton registration returns the same instance each time`, function () {320 container.register(Registration.aliasTo(ISingleton, 'alias'));321 const actual1 = container.get('alias');322 assert.instanceOf(actual1, Singleton, `actual1`);323 const actual2 = container.get('alias');324 assert.instanceOf(actual2, Singleton, `actual2`);325 assert.strictEqual(actual1, actual2, `actual1`);326 assert.deepStrictEqual(327 get.calls,328 [329 ['alias'],330 [ISingleton],331 ['alias'],332 [ISingleton],333 ],334 `get.calls`,335 );336 });337 it(`string alias to instance registration returns the same instance each time`, function () {338 container.register(Registration.aliasTo(IInstance, 'alias'));339 const actual1 = container.get('alias');340 assert.instanceOf(actual1, Instance, `actual1`);341 const actual2 = container.get('alias');342 assert.instanceOf(actual2, Instance, `actual2`);343 assert.strictEqual(actual1, instance, `actual1`);344 assert.strictEqual(actual2, instance, `actual2`);345 assert.deepStrictEqual(346 get.calls,347 [348 ['alias'],349 [IInstance],350 ['alias'],351 [IInstance],352 ],353 `get.calls`,354 );355 });356 it(`string alias to callback registration is invoked each time`, function () {357 container.register(Registration.aliasTo(ICallback, 'alias'));358 const actual1 = container.get('alias');359 assert.instanceOf(actual1, Callback, `actual1`);360 const actual2 = container.get('alias');361 assert.instanceOf(actual2, Callback, `actual2`);362 assert.notStrictEqual(actual1, actual2, `actual1`);363 assert.deepStrictEqual(364 callback.calls,365 [366 [container, container, container.getResolver(ICallback)],367 [container, container, container.getResolver(ICallback)],368 ],369 `callback.calls`,370 );371 assert.deepStrictEqual(372 get.calls,373 [374 ['alias'],375 [ICallback],376 ['alias'],377 [ICallback],378 ],379 `get.calls`,380 );381 });382 });383 // describe('parent without inject decorator', function () {384 // function decorator(): ClassDecorator { return (target: any) => target; }385 // interface IParent { dep: any; }386 // let IParent: InterfaceSymbol<IParent>;387 // function register(cls: any) {388 // IParent = DI.createInterface<IParent>('IParent', x => x.transient(cls));389 // }390 // it(`transient child registration throws`, function () {391 // @decorator()392 // class Parent implements IParent { constructor(public dep: ITransient) {} }393 // register(Parent);394 // assert.throws(() => container.get(IParent), /5/, `() => container.get(IParent)`);395 // });396 // it(`singleton child registration throws`, function () {397 // @decorator()398 // class Parent implements IParent { constructor(public dep: ISingleton) {} }399 // register(Parent);400 // assert.throws(() => container.get(IParent), /5/, `() => container.get(IParent)`);401 // });402 // it(`instance child registration throws`, function () {403 // @decorator()404 // class Parent implements IParent { constructor(public dep: IInstance) {} }405 // register(Parent);406 // assert.throws(() => container.get(IParent), /5/, `() => container.get(IParent)`);407 // });408 // it(`callback child registration throws`, function () {409 // @decorator()410 // class Parent implements IParent { constructor(public dep: ICallback) {} }411 // register(Parent);412 // assert.throws(() => container.get(IParent), /5/, `() => container.get(IParent)`);413 // });414 // });415 describe('transient parent', function () {416 interface ITransientParent { dep: any }417 let ITransientParent: InterfaceSymbol<ITransientParent>;418 function register(cls: any) {419 ITransientParent = DI.createInterface<ITransientParent>('ITransientParent', x => x.transient(cls));420 }421 it(`transient child registration returns a new instance each time`, function () {422 @inject(ITransient)423 class TransientParent implements ITransientParent { public constructor(public dep: ITransient) {} }424 register(TransientParent);425 const actual1 = container.get(ITransientParent);426 assert.instanceOf(actual1, TransientParent, `actual1`);427 assert.instanceOf(actual1.dep, Transient, `actual1.dep`);428 const actual2 = container.get(ITransientParent);429 assert.instanceOf(actual2, TransientParent, `actual2`);430 assert.instanceOf(actual2.dep, Transient, `actual2.dep`);431 assert.notStrictEqual(actual1, actual2, `actual1`);432 assert.notStrictEqual(actual1.dep, actual2.dep, `actual1.dep`);433 assert.deepStrictEqual(434 get.calls,435 [436 [ITransientParent],437 [ITransient],438 [ITransientParent],439 [ITransient],440 ],441 `get.calls`,442 );443 });444 it(`singleton child registration returns the same instance each time`, function () {445 @inject(ISingleton)446 class TransientParent implements ITransientParent { public constructor(public dep: ISingleton) {} }447 register(TransientParent);448 const actual1 = container.get(ITransientParent);449 assert.instanceOf(actual1, TransientParent, `actual1`);450 assert.instanceOf(actual1.dep, Singleton, `actual1.dep`);451 const actual2 = container.get(ITransientParent);452 assert.instanceOf(actual2, TransientParent, `actual2`);453 assert.instanceOf(actual2.dep, Singleton, `actual2.dep`);454 assert.notStrictEqual(actual1, actual2, `actual1`);455 assert.strictEqual(actual1.dep, actual2.dep, `actual1.dep`);456 assert.deepStrictEqual(457 get.calls,458 [459 [ITransientParent],460 [ISingleton],461 [ITransientParent],462 [ISingleton],463 ],464 `get.calls`,465 );466 });467 it(`instance child registration returns the same instance each time`, function () {468 @inject(IInstance)469 class TransientParent implements ITransientParent { public constructor(public dep: IInstance) {} }470 register(TransientParent);471 const actual1 = container.get(ITransientParent);472 assert.instanceOf(actual1, TransientParent, `actual1`);473 assert.instanceOf(actual1.dep, Instance, `actual1.dep`);474 const actual2 = container.get(ITransientParent);475 assert.instanceOf(actual2, TransientParent, `actual2`);476 assert.instanceOf(actual2.dep, Instance, `actual2.dep`);477 assert.notStrictEqual(actual1, actual2, `actual1`);478 assert.strictEqual(actual1.dep, actual2.dep, `actual1.dep`);479 assert.deepStrictEqual(480 get.calls,481 [482 [ITransientParent],483 [IInstance],484 [ITransientParent],485 [IInstance],486 ],487 `get.calls`,488 );489 });490 it(`callback child registration is invoked each time`, function () {491 @inject(ICallback)492 class TransientParent implements ITransientParent { public constructor(public dep: ICallback) {} }493 register(TransientParent);494 const actual1 = container.get(ITransientParent);495 assert.instanceOf(actual1, TransientParent, `actual1`);496 assert.instanceOf(actual1.dep, Callback, `actual1.dep`);497 const actual2 = container.get(ITransientParent);498 assert.instanceOf(actual2, TransientParent, `actual2`);499 assert.instanceOf(actual2.dep, Callback, `actual2.dep`);500 assert.notStrictEqual(actual1, actual2, `actual1`);501 assert.notStrictEqual(actual1.dep, actual2.dep, `actual1.dep`);502 assert.deepStrictEqual(503 callback.calls,504 [505 [container, container, container.getResolver(ICallback)],506 [container, container, container.getResolver(ICallback)],507 ],508 `callback.calls`,509 );510 assert.deepStrictEqual(511 get.calls,512 [513 [ITransientParent],514 [ICallback],515 [ITransientParent],516 [ICallback],517 ],518 `get.calls`,519 );520 });521 });522 describe('singleton parent', function () {523 interface ISingletonParent { dep: any }524 let ISingletonParent: InterfaceSymbol<ISingletonParent>;525 function register(cls: any) {526 ISingletonParent = DI.createInterface<ISingletonParent>('ISingletonParent', x => x.singleton(cls));527 }528 it(`transient child registration is reused by the singleton parent`, function () {529 @inject(ITransient)530 class SingletonParent implements ISingletonParent { public constructor(public dep: ITransient) {} }531 register(SingletonParent);532 const actual1 = container.get(ISingletonParent);533 assert.instanceOf(actual1, SingletonParent, `actual1`);534 assert.instanceOf(actual1.dep, Transient, `actual1.dep`);535 const actual2 = container.get(ISingletonParent);536 assert.instanceOf(actual2, SingletonParent, `actual2`);537 assert.instanceOf(actual2.dep, Transient, `actual2.dep`);538 assert.strictEqual(actual1, actual2, `actual1`);539 assert.strictEqual(actual1.dep, actual2.dep, `actual1.dep`);540 assert.deepStrictEqual(541 get.calls,542 [543 [ISingletonParent],544 [ITransient],545 [ISingletonParent],546 ],547 `get.calls`,548 );549 });550 it(`singleton registration is reused by the singleton parent`, function () {551 @inject(ISingleton)552 class SingletonParent implements ISingletonParent { public constructor(public dep: ISingleton) {} }553 register(SingletonParent);554 const actual1 = container.get(ISingletonParent);555 assert.instanceOf(actual1, SingletonParent, `actual1`);556 assert.instanceOf(actual1.dep, Singleton, `actual1.dep`);557 const actual2 = container.get(ISingletonParent);558 assert.instanceOf(actual2, SingletonParent, `actual2`);559 assert.instanceOf(actual2.dep, Singleton, `actual2.dep`);560 assert.strictEqual(actual1, actual2, `actual1`);561 assert.strictEqual(actual1.dep, actual2.dep, `actual1.dep`);562 assert.deepStrictEqual(563 get.calls,564 [565 [ISingletonParent],566 [ISingleton],567 [ISingletonParent],568 ],569 `get.calls`,570 );571 });572 it(`instance registration is reused by the singleton parent`, function () {573 @inject(IInstance)574 class SingletonParent implements ISingletonParent { public constructor(public dep: IInstance) {} }575 register(SingletonParent);576 const actual1 = container.get(ISingletonParent);577 assert.instanceOf(actual1, SingletonParent, `actual1`);578 assert.instanceOf(actual1.dep, Instance, `actual1.dep`);579 const actual2 = container.get(ISingletonParent);580 assert.instanceOf(actual2, SingletonParent, `actual2`);581 assert.instanceOf(actual2.dep, Instance, `actual2.dep`);582 assert.strictEqual(actual1, actual2, `actual1`);583 assert.strictEqual(actual1.dep, actual2.dep, `actual1.dep`);584 assert.deepStrictEqual(585 get.calls,586 [587 [ISingletonParent],588 [IInstance],589 [ISingletonParent],590 ],591 `get.calls`,592 );593 });594 it(`callback registration is reused by the singleton parent`, function () {595 @inject(ICallback)596 class SingletonParent implements ISingletonParent { public constructor(public dep: ICallback) {} }597 register(SingletonParent);598 const actual1 = container.get(ISingletonParent);599 assert.instanceOf(actual1, SingletonParent, `actual1`);600 assert.instanceOf(actual1.dep, Callback, `actual1.dep`);601 const actual2 = container.get(ISingletonParent);602 assert.instanceOf(actual2, SingletonParent, `actual2`);603 assert.instanceOf(actual2.dep, Callback, `actual2.dep`);604 assert.strictEqual(actual1, actual2, `actual1`);605 assert.strictEqual(actual1.dep, actual2.dep, `actual1.dep`);606 assert.deepStrictEqual(607 callback.calls,608 [609 [container, container, container.getResolver(ICallback)],610 ],611 `callback.calls`,612 );613 assert.deepStrictEqual(614 get.calls,615 [616 [ISingletonParent],617 [ICallback],618 [ISingletonParent],619 ],620 `get.calls`,621 );622 });623 });624 describe('instance parent', function () {625 interface IInstanceParent { dep: any }626 let IInstanceParent: InterfaceSymbol<IInstanceParent>;627 let instanceParent: IInstanceParent;628 function register(cls: any) {629 instanceParent = container.get(cls);630 get.reset();631 IInstanceParent = DI.createInterface<IInstanceParent>('IInstanceParent', x => x.instance(instanceParent));632 }633 it(`transient registration is reused by the instance parent`, function () {634 @inject(ITransient)635 class InstanceParent implements IInstanceParent { public constructor(public dep: ITransient) {} }636 register(InstanceParent);637 const actual1 = container.get(IInstanceParent);638 assert.instanceOf(actual1, InstanceParent, `actual1`);639 assert.instanceOf(actual1.dep, Transient, `actual1.dep`);640 const actual2 = container.get(IInstanceParent);641 assert.instanceOf(actual2, InstanceParent, `actual2`);642 assert.instanceOf(actual2.dep, Transient, `actual2.dep`);643 assert.strictEqual(actual1, actual2, `actual1`);644 assert.strictEqual(actual1.dep, actual2.dep, `actual1.dep`);645 assert.deepStrictEqual(646 get.calls,647 [648 [IInstanceParent],649 [IInstanceParent],650 ],651 `get.calls`,652 );653 });654 it(`singleton registration is reused by the instance parent`, function () {655 @inject(ISingleton)656 class InstanceParent implements IInstanceParent { public constructor(public dep: ISingleton) {} }657 register(InstanceParent);658 const actual1 = container.get(IInstanceParent);659 assert.instanceOf(actual1, InstanceParent, `actual1`);660 assert.instanceOf(actual1.dep, Singleton, `actual1.dep`);661 const actual2 = container.get(IInstanceParent);662 assert.instanceOf(actual2, InstanceParent, `actual2`);663 assert.instanceOf(actual2.dep, Singleton, `actual2.dep`);664 assert.strictEqual(actual1, actual2, `actual1`);665 assert.strictEqual(actual1.dep, actual2.dep, `actual1.dep`);666 assert.deepStrictEqual(667 get.calls,668 [669 [IInstanceParent],670 [IInstanceParent],671 ],672 `get.calls`,673 );674 });675 it(`instance registration is reused by the instance parent`, function () {676 @inject(IInstance)677 class InstanceParent implements IInstanceParent { public constructor(public dep: IInstance) {} }678 register(InstanceParent);679 const actual1 = container.get(IInstanceParent);680 assert.instanceOf(actual1, InstanceParent, `actual1`);681 assert.instanceOf(actual1.dep, Instance, `actual1.dep`);682 const actual2 = container.get(IInstanceParent);683 assert.instanceOf(actual2, InstanceParent, `actual2`);684 assert.instanceOf(actual2.dep, Instance, `actual2.dep`);685 assert.strictEqual(actual1, actual2, `actual1`);686 assert.strictEqual(actual1.dep, actual2.dep, `actual1.dep`);687 assert.deepStrictEqual(688 get.calls,689 [690 [IInstanceParent],691 [IInstanceParent],692 ],693 `get.calls`,694 );695 });696 it(`callback registration is reused by the instance parent`, function () {697 @inject(ICallback)698 class InstanceParent implements IInstanceParent { public constructor(public dep: ICallback) {} }699 register(InstanceParent);700 const actual1 = container.get(IInstanceParent);701 assert.instanceOf(actual1, InstanceParent, `actual1`);702 assert.instanceOf(actual1.dep, Callback, `actual1.dep`);703 const actual2 = container.get(IInstanceParent);704 assert.instanceOf(actual2, InstanceParent, `actual2`);705 assert.instanceOf(actual2.dep, Callback, `actual2.dep`);706 assert.strictEqual(actual1, actual2, `actual1`);707 assert.strictEqual(actual1.dep, actual2.dep, `actual1.dep`);708 assert.deepStrictEqual(709 callback.calls,710 [711 [container, container, container.getResolver(ICallback)],712 ],713 `callback.calls`,714 );715 assert.deepStrictEqual(716 get.calls,717 [718 [IInstanceParent],719 [IInstanceParent],720 ],721 `get.calls`,722 );723 });724 });725});726describe('defer registration', function () {727 class FakeCSSService {728 public constructor(public data: any) {}729 }730 class FakeCSSHandler {731 public register(container: IContainer, data) {732 container.register(733 Registration.instance(734 FakeCSSService,735 new FakeCSSService(data)736 )737 );738 }739 }740 it(`enables the handler class to provide registrations for data`, function () {741 const container = DI.createContainer();742 const data = {};743 container.register(744 Registration.singleton('.css', FakeCSSHandler)745 );746 container.register(747 Registration.defer('.css', data)748 );749 const service = container.get(FakeCSSService);750 assert.strictEqual(service.data, data);751 });752 it(`passes the params to the container's register method if no handler is found`, function () {753 const container = DI.createContainer();754 const data = {755 wasCalled: false,756 register() {757 this.wasCalled = true;758 }759 };760 container.register(761 Registration.defer('.css', data)762 );763 assert.strictEqual(data.wasCalled, true);764 });765 [766 {767 name: 'string',768 value: 'some string value'769 },770 {771 name: 'boolean',772 value: true773 },774 {775 name: 'number',776 value: 42777 }778 ].forEach(x => {779 it(`does not pass ${x.name} params to the container's register when no handler is found`, function () {780 const container = DI.createContainer();781 container.register(782 Registration.defer('.css', x.value)783 );784 });785 });786 // TODO: fix test setup for emitDecoratorMetadata787 // it('can inject dependencies based on TS metadata', function () {788 // const deco: ClassDecorator = function (target) { return target; };789 // class Foo {}790 // @deco791 // class Bar {792 // public constructor(793 // public readonly foo: Foo794 // ) {}795 // }796 // const bar = DI.createContainer().get(Bar);797 // assert.instanceOf(bar.foo, Foo);798 // });...
tree-selector.test.js
Source:tree-selector.test.js
1import {2 TreeSelector,3 SELECTION_EMPTY,4 SELECTION_PARTIAL,5 SELECTION_FULL,6} from '../tree-selector';7import R from 'ramda';8const hierarchy = {9 root: { name: 'Root', children: ['a', 'b'] },10 a: { name: 'A', parentId: 'root', children: ['a1', 'a2'] },11 a1: { name: 'A1', parentId: 'a', children: ['a11'] },12 a2: { name: 'A2', parentId: 'a', children: [] },13 a11: { name: 'A11', parentId: 'a1', children: [] },14 b: { name: 'B', parentId: 'root', children: ['b1', 'b2', 'b3'] },15 b1: { name: 'B1', parentId: 'b', children: ['b11'] },16 b2: { name: 'B2', parentId: 'b', children: [] },17 b3: { name: 'B3', parentId: 'b', children: [] },18 b11: { name: 'B11', parentId: 'b1', children: ['b111'] },19 b111: { name: 'B111', parentId: 'b11', children: [] },20};21const initialSelection = R.map(R.always(SELECTION_FULL), hierarchy);22const treeSelector = new TreeSelector({23 parent: (nodeId, hierarchy) => hierarchy[nodeId].parentId,24 children: (nodeId, hierarchy) => hierarchy[nodeId].children,25 isChild: (nodeId, hierarchy) => hierarchy[nodeId].children.length === 0,26 all: (predicate, hierarchy) =>27 (function*() {28 for (const id in hierarchy) if (predicate(id)) yield id;29 })(),30 rootId: _ => 'root',31 name: (nodeId, hierarchy) => hierarchy[nodeId].name,32});33const toggle = (nodeId, selection = initialSelection) =>34 treeSelector.toggle(nodeId, selection, hierarchy);35const select = (nodeId, state, selection = initialSelection) =>36 treeSelector.select(nodeId, state, selection, hierarchy);37const forAll = () => true;38const selectAllLeaves = (predicate, newState, selection = initialSelection) =>39 treeSelector.selectAllLeaves(predicate, newState, selection, hierarchy);40test('toggling selection of a leaf node works', () => {41 const actual1 = toggle('a2');42 expect(actual1).toEqual({43 ...initialSelection,44 a2: SELECTION_EMPTY,45 a: SELECTION_PARTIAL,46 root: SELECTION_PARTIAL,47 });48 const actual2 = toggle('a2', actual1);49 expect(actual2).toEqual(initialSelection);50});51test('setting selection of a leaf node works', () => {52 const actual1 = select('a2', SELECTION_EMPTY);53 expect(actual1).toEqual({54 ...initialSelection,55 a2: SELECTION_EMPTY,56 a: SELECTION_PARTIAL,57 root: SELECTION_PARTIAL,58 });59 const actual2 = select('a2', SELECTION_FULL, actual1);60 expect(actual2).toEqual(initialSelection);61});62test('setting selection of a leaf node is idempotent', () => {63 const actual1 = select('a2', SELECTION_EMPTY, select('a2', SELECTION_EMPTY));64 expect(actual1).toEqual({65 ...initialSelection,66 a2: SELECTION_EMPTY,67 a: SELECTION_PARTIAL,68 root: SELECTION_PARTIAL,69 });70 const actual2 = select(71 'a2',72 SELECTION_FULL,73 select('a2', SELECTION_FULL, actual1)74 );75 expect(actual2).toEqual(initialSelection);76});77test('toggling selection of a non-leaf node works', () => {78 const actual1 = toggle('a');79 expect(actual1).toEqual({80 ...initialSelection,81 a: SELECTION_EMPTY,82 a1: SELECTION_EMPTY,83 a11: SELECTION_EMPTY,84 a2: SELECTION_EMPTY,85 root: SELECTION_PARTIAL,86 });87 const actual2 = toggle('a', actual1);88 expect(actual2).toEqual(initialSelection);89});90test('setting selection of a non-leaf node works', () => {91 const actual1 = select('a', SELECTION_EMPTY);92 expect(actual1).toEqual({93 ...initialSelection,94 a: SELECTION_EMPTY,95 a1: SELECTION_EMPTY,96 a11: SELECTION_EMPTY,97 a2: SELECTION_EMPTY,98 root: SELECTION_PARTIAL,99 });100 const actual2 = select('a', SELECTION_FULL, actual1);101 expect(actual2).toEqual(initialSelection);102});103test('setting selection of a non-leaf is idempotent', () => {104 const actual1 = select('a', SELECTION_EMPTY, select('a', SELECTION_EMPTY));105 expect(actual1).toEqual({106 ...initialSelection,107 a: SELECTION_EMPTY,108 a1: SELECTION_EMPTY,109 a11: SELECTION_EMPTY,110 a2: SELECTION_EMPTY,111 root: SELECTION_PARTIAL,112 });113 const actual2 = select(114 'a',115 SELECTION_FULL,116 select('a', SELECTION_FULL, actual1)117 );118 expect(actual2).toEqual(initialSelection);119});120test('setting selection of all leaves works', () => {121 const actual1 = selectAllLeaves(forAll, SELECTION_EMPTY);122 expect(actual1).toEqual({123 root: SELECTION_EMPTY,124 a: SELECTION_EMPTY,125 b: SELECTION_EMPTY,126 a1: SELECTION_EMPTY,127 a11: SELECTION_EMPTY,128 a2: SELECTION_EMPTY,129 b1: SELECTION_EMPTY,130 b2: SELECTION_EMPTY,131 b3: SELECTION_EMPTY,132 b11: SELECTION_EMPTY,133 b111: SELECTION_EMPTY,134 });135 const actual2 = selectAllLeaves(forAll, SELECTION_FULL, actual1);136 expect(actual2).toEqual(initialSelection);137});138test('setting selection of all leaves is idempotent', () => {139 const actual1 = selectAllLeaves(140 forAll,141 SELECTION_EMPTY,142 selectAllLeaves(forAll, SELECTION_EMPTY)143 );144 expect(actual1).toEqual({145 root: SELECTION_EMPTY,146 a: SELECTION_EMPTY,147 b: SELECTION_EMPTY,148 a1: SELECTION_EMPTY,149 a11: SELECTION_EMPTY,150 a2: SELECTION_EMPTY,151 b1: SELECTION_EMPTY,152 b2: SELECTION_EMPTY,153 b3: SELECTION_EMPTY,154 b11: SELECTION_EMPTY,155 b111: SELECTION_EMPTY,156 });157 const actual2 = selectAllLeaves(158 forAll,159 SELECTION_FULL,160 selectAllLeaves(forAll, SELECTION_FULL, actual1)161 );162 expect(actual2).toEqual(initialSelection);163});164test('setting selection of a set of leaves works', () => {165 const predicate = id => id === 'a2' || id === 'b3';166 const actual1 = selectAllLeaves(predicate, SELECTION_EMPTY);167 expect(actual1).toEqual({168 root: SELECTION_PARTIAL,169 a: SELECTION_PARTIAL,170 b: SELECTION_PARTIAL,171 a1: SELECTION_FULL,172 a11: SELECTION_FULL,173 a2: SELECTION_EMPTY,174 b1: SELECTION_FULL,175 b2: SELECTION_FULL,176 b3: SELECTION_EMPTY,177 b11: SELECTION_FULL,178 b111: SELECTION_FULL,179 });180 const actual2 = selectAllLeaves(predicate, SELECTION_FULL, actual1);181 expect(actual2).toEqual(initialSelection);182});183test('setting selection of a set of leaves is idempotent', () => {184 const predicate = id => id === 'a2' || id === 'b3';185 const actual1 = selectAllLeaves(186 predicate,187 SELECTION_EMPTY,188 selectAllLeaves(predicate, SELECTION_EMPTY)189 );190 expect(actual1).toEqual({191 root: SELECTION_PARTIAL,192 a: SELECTION_PARTIAL,193 b: SELECTION_PARTIAL,194 a1: SELECTION_FULL,195 a11: SELECTION_FULL,196 a2: SELECTION_EMPTY,197 b1: SELECTION_FULL,198 b2: SELECTION_FULL,199 b3: SELECTION_EMPTY,200 b11: SELECTION_FULL,201 b111: SELECTION_FULL,202 });203 const actual2 = selectAllLeaves(204 predicate,205 SELECTION_FULL,206 selectAllLeaves(predicate, SELECTION_FULL, actual1)207 );208 expect(actual2).toEqual(initialSelection);209});210test('Pre-human description for everything and nothing works', () => {211 const actual1 = treeSelector.describe(initialSelection, hierarchy);212 expect(actual1).toEqual('Everything');213 const actual2 = treeSelector.describe(214 {215 root: SELECTION_EMPTY,216 a: SELECTION_EMPTY,217 a1: SELECTION_EMPTY,218 a11: SELECTION_EMPTY,219 a2: SELECTION_EMPTY,220 b: SELECTION_EMPTY,221 b1: SELECTION_EMPTY,222 b2: SELECTION_EMPTY,223 b3: SELECTION_EMPTY,224 b11: SELECTION_EMPTY,225 b111: SELECTION_EMPTY,226 },227 hierarchy228 );229 expect(actual2).toEqual('Nothing');230});231test('Pre-human description for deep selection works', () => {232 const actual1 = treeSelector.describe(233 {234 root: SELECTION_PARTIAL,235 a: SELECTION_FULL,236 a1: SELECTION_FULL,237 a11: SELECTION_FULL,238 a2: SELECTION_FULL,239 b: SELECTION_PARTIAL,240 b1: SELECTION_EMPTY,241 b11: SELECTION_EMPTY,242 b111: SELECTION_EMPTY,243 b2: SELECTION_FULL,244 b3: SELECTION_FULL,245 },246 hierarchy247 );248 expect(actual1).toEqual(['Everything', 'except', ['B1']]);249 const actual2 = treeSelector.describe(250 {251 root: SELECTION_PARTIAL,252 a: SELECTION_FULL,253 a1: SELECTION_FULL,254 a11: SELECTION_FULL,255 a2: SELECTION_FULL,256 b: SELECTION_PARTIAL,257 b1: SELECTION_EMPTY,258 b11: SELECTION_EMPTY,259 b111: SELECTION_EMPTY,260 b2: SELECTION_EMPTY,261 b3: SELECTION_FULL,262 },263 hierarchy264 );265 expect(actual2).toEqual(['Everything', 'except', ['B', 'except', ['B3']]]);266});267test('Retrieving selected IDs for everything and nothing works', () => {268 const actual1 = treeSelector.selectedIds(initialSelection, hierarchy);269 expect(actual1).toEqual([]);270 const actual2 = treeSelector.selectedIds(271 {272 root: SELECTION_EMPTY,273 a: SELECTION_EMPTY,274 a1: SELECTION_EMPTY,275 a11: SELECTION_EMPTY,276 a2: SELECTION_EMPTY,277 b: SELECTION_EMPTY,278 b1: SELECTION_EMPTY,279 b2: SELECTION_EMPTY,280 b3: SELECTION_EMPTY,281 b11: SELECTION_EMPTY,282 b111: SELECTION_EMPTY,283 },284 hierarchy285 );286 expect(actual2).toEqual(null);287});288test('Retrieving selected IDs for a mixed selection works', () => {289 const actual1 = treeSelector.selectedIds(290 {291 root: SELECTION_PARTIAL,292 a: SELECTION_FULL,293 a1: SELECTION_FULL,294 a11: SELECTION_FULL,295 a2: SELECTION_FULL,296 b: SELECTION_PARTIAL,297 b1: SELECTION_EMPTY,298 b11: SELECTION_EMPTY,299 b111: SELECTION_EMPTY,300 b2: SELECTION_FULL,301 b3: SELECTION_FULL,302 },303 hierarchy304 );305 expect(new Set(actual1)).toEqual(new Set(['a', 'b2', 'b3']));306 const actual2 = treeSelector.selectedIds(307 {308 root: SELECTION_PARTIAL,309 a: SELECTION_FULL,310 a1: SELECTION_FULL,311 a11: SELECTION_FULL,312 a2: SELECTION_FULL,313 b: SELECTION_PARTIAL,314 b1: SELECTION_EMPTY,315 b11: SELECTION_EMPTY,316 b111: SELECTION_EMPTY,317 b2: SELECTION_EMPTY,318 b3: SELECTION_FULL,319 },320 hierarchy321 );322 expect(new Set(actual2)).toEqual(new Set(['a', 'b3']));...
functions.test.js
Source:functions.test.js
1// IMPORT MODULES under test here:2import { 3 addExclamationPoints, divideThenMultiply, getLastItem, getRandomNumber, getSecondItem, makeLuckyGreeting, multiplyBy12ThenHalve, multiplyBySeven, returnAsAnArray, returnAsAString,4} from '../functions.js';5const { test, skip } = QUnit;6test('addExclamationPoints should return a string with 3 exclamation points added to the end', (expect) => {7 const expected1 = 'puppy!!!';8 const actual1 = addExclamationPoints('puppy');9 const expected2 = 'muppy!!!';10 const actual2 = addExclamationPoints('muppy');11 expect.equal(actual1, expected1, 'should return "puppy!!!"');12 expect.equal(actual2, expected2, 'should return "muppy!!!"');13});14test('this test should multiply a number by 7', (expect) => {15 const expected1 = 28;16 const actual1 = multiplyBySeven(4);17 const expected2 = 14;18 const actual2 = multiplyBySeven(2);19 expect.equal(actual1, expected1, 'should return 28');20 expect.equal(actual2, expected2, 'should return 14');21});22test('This function should take in a number and multiply it by 12 then cut the result in half', (expect) => {23 const expected1 = 24;24 const actual1 = multiplyBy12ThenHalve(4);25 const expected2 = 12;26 const actual2 = multiplyBy12ThenHalve(2);27 expect.equal(actual1, expected1, 'should return 24');28 expect.equal(actual2, expected2, 'should return 12');29});30test('This function should take in three numbers, divide the first by the second, then multiply the result by the third', (expect) => {31 const expected1 = 10;32 const actual1 = divideThenMultiply(8, 4, 5);33 const expected2 = 6;34 const actual2 = divideThenMultiply(10, 5, 3);35 expect.equal(actual1, expected1, 'should return 10');36 expect.equal(actual2, expected2, 'should return 6');37});38test('This function should take in three numbers and return those numbers in an array', (expect) => {39 const expected1 = [8, 4, 5];40 const actual1 = returnAsAnArray(8, 4, 5);41 const expected2 = [1, 2, 3];42 const actual2 = returnAsAnArray(1, 2, 3);43 expect.deepEqual(actual1, expected1, 'should return [8, 4, 5]');44 expect.deepEqual(actual2, expected2, 'should return [1, 2, 3]');45});46test('This function should take in three numbers and return those numbers mushed together as a string', (expect) => {47 const expected1 = '845';48 const actual1 = returnAsAString(8, 4, 5);49 const expected2 = '123';50 const actual2 = returnAsAString(1, 2, 3);51 expect.equal(actual1, expected1, 'should return "845"');52 expect.equal(actual2, expected2, 'should return "123"');53});54test("This function should take in two numbers and return a greeting announcing that the sum of those numbers is today's lucky number", (expect) => {55 const expected1 = 'Hello! Your lucky number for the day is 12.';56 const actual1 = makeLuckyGreeting(8, 4);57 const expected2 = 'Hello! Your lucky number for the day is 13.';58 const actual2 = makeLuckyGreeting(7, 6) ;59 expect.equal(actual1, expected1, 'Hello! Your lucky number for the day is 12');60 expect.equal(actual2, expected2, 'Hello! Your lucky number for the day is 123');61});62test("This function should take an array and return the LAST item in the array, no matter the array's length", (expect) => {63 const expected1 = 'plum';64 const actual1 = getLastItem(['kiwi', 'apple', 'orange', 'plum']);65 const expected2 = 'bob';66 const actual2 = getLastItem(['jeff', 'steve', 'bob']);67 expect.equal(actual1, expected1, 'plum');68 expect.equal(actual2, expected2, 'bob');69});70test('This function should take an array and return the second item in the array', (expect) => {71 const expected1 = 'apple';72 const actual1 = getSecondItem(['kiwi', 'apple', 'orange', 'plum']);73 const expected2 = 'steve';74 const actual2 = getSecondItem(['jeff', 'steve', 'bob']);75 expect.equal(actual1, expected1, 'apple');76 expect.equal(actual2, expected2, 'steve');77});78test('This function should make a random number between 0 and 5', (expect) => {79 const expected1 = true;80 const expected2 = 'number';81 const actual2 = getRandomNumber();82 expect.equal(actual2 >= 0, actual2 <= 5, expected1);83 expect.equal(typeof actual2, expected2);...
Using AI Code Generation
1import { actual1 } from 'ng-mocks';2import { actual2 } from 'ng-mocks';3import { actual3 } from 'ng-mocks';4import { actual4 } from 'ng-mocks';5import { actual5 } from 'ng-mocks';6import { actual6 } from 'ng-mocks';7import { actual7 } from 'ng-mocks';8import { actual8 } from 'ng-mocks';9import { actual9 } from 'ng-mocks';10import { actual10 } from 'ng-mocks';11import { actual11 } from 'ng-mocks';12import { actual12 } from 'ng-mocks';13import { actual13 } from 'ng-mocks';14import { actual14 } from 'ng-mocks';15import { actual15 } from 'ng-mocks';16import { actual16 } from 'ng-mocks';17import { actual17 } from 'ng-mocks';18import { actual18 } from 'ng-mocks';19import { actual19 } from 'ng-mocks';20import { actual20 } from 'ng-mocks';21import { actual21 } from 'ng-mocks';22import { actual22 } from 'ng-mocks';
Using AI Code Generation
1const actual1 = require('ng-mocks').actual1;2const actual2 = require('ng-mocks').actual2;3const actual3 = require('ng-mocks').actual3;4const actual4 = require('ng-mocks').actual4;5const actual5 = require('ng-mocks').actual5;6const actual6 = require('ng-mocks').actual6;7actual1('a', 'b', 'c', 'd', 'e', 'f', 'g');8actual2('a', 'b', 'c', 'd', 'e', 'f', 'g');9actual3('a', 'b', 'c', 'd', 'e', 'f', 'g');10actual4('a', 'b', 'c', 'd', 'e', 'f', 'g');11actual5('a', 'b', 'c', 'd', 'e', 'f', 'g');12actual6('a', 'b', 'c', 'd', 'e', 'f', 'g');13const mock1 = require('ng-mocks').mock1;14const mock2 = require('ng-mocks').mock2;15const mock3 = require('ng-mocks').mock3;16const mock4 = require('ng-mocks').mock4;17const mock5 = require('ng-mocks').mock5;18const mock6 = require('ng-mocks').mock6;19describe('ng-mocks', () => {20 it('should mock actual1', () => {21 const actual1 = mock1('a', 'b', 'c', 'd', 'e', 'f', 'g');22 expect(actual1).toBe('a');23 });24 it('should mock actual2', () => {25 const actual2 = mock2('a', 'b', 'c', 'd', 'e', 'f', 'g');26 expect(actual2).toBe('b');27 });28 it('should mock actual3', () => {29 const actual3 = mock3('a', 'b', 'c', 'd', 'e', 'f', 'g');30 expect(actual3).toBe('c');31 });32 it('should mock actual4', () => {33 const actual4 = mock4('a', 'b', 'c',
Using AI Code Generation
1import {actual1} from 'ng-mocks';2import {actual2} from 'ng-mocks';3import {actual1} from 'ng-mocks';4import {actual2} from 'ng-mocks';5import {actual1} from 'ng-mocks';6import {TestComponent} from './test.component';7describe('TestComponent', () => {8 it('should create an instance', () => {9 const actual = actual1(TestComponent);10 expect(actual).toBeTruthy();11 });12});13import {actual2} from 'ng-mocks';14import {TestComponent} from './test.component';15describe('TestComponent', () => {16 it('should create an instance', () => {17 const actual = actual2(TestComponent);18 expect(actual).toBeTruthy();19 });20});
Using AI Code Generation
1import {actual1} from 'ng-mocks';2import {actual1} from 'ng-mocks/dist/lib/mock-helper';3import {actual1} from 'ng-mocks/dist/lib/mock-helper/actual';4import {actual1} from 'ng-mocks/dist/lib/mock-helper/actual/actual';5import {actual1} from 'ng-mocks';6import {actual1} from 'ng-mocks/dist/lib/mock-helper';7import {actual1} from 'ng-mocks/dist/lib/mock-helper/actual';8import {actual1} from 'ng-mocks/dist/lib/mock-helper/actual/actual';9import {actual1} from 'ng-mocks';10import {actual1} from 'ng-mocks/dist/lib/mock-helper';11import {actual1} from 'ng-mocks/dist/lib/mock-helper/actual';12import {actual1} from 'ng-mocks/dist/lib/mock-helper/actual/actual';13import {actual1} from 'ng-mocks';14import {actual1} from 'ng-mocks/dist/lib/mock-helper';15import {actual1} from 'ng-mocks/dist/lib/mock-helper/actual';16import {actual1} from 'ng-mocks/dist/lib/mock-helper/actual/actual';17import {actual1} from 'ng-mocks';18import {actual1} from 'ng-mocks/dist/lib
Using AI Code Generation
1const actual1 = ngMocks.findInstance(ChildComponent);2const actual2 = ngMocks.findInstance(ChildComponent);3const actual3 = ngMocks.findInstance(ChildComponent);4const actual4 = ngMocks.findInstance(ChildComponent);5const actual5 = ngMocks.findInstance(ChildComponent);6const actual6 = ngMocks.findInstance(ChildComponent);7const actual7 = ngMocks.findInstance(ChildComponent);8const actual8 = ngMocks.findInstance(ChildComponent);9const actual9 = ngMocks.findInstance(ChildComponent);10const actual10 = ngMocks.findInstance(ChildComponent);11const actual11 = ngMocks.findInstance(ChildComponent);12const actual12 = ngMocks.findInstance(ChildComponent);13const actual13 = ngMocks.findInstance(ChildComponent);14const actual14 = ngMocks.findInstance(ChildComponent);15const actual15 = ngMocks.findInstance(ChildComponent);16const actual16 = ngMocks.findInstance(ChildComponent);17const actual17 = ngMocks.findInstance(ChildComponent);18const actual18 = ngMocks.findInstance(ChildComponent);19const actual19 = ngMocks.findInstance(ChildComponent);20const actual20 = ngMocks.findInstance(ChildComponent);21const actual21 = ngMocks.findInstance(ChildComponent);
Using AI Code Generation
1import { actual1 } from 'ng-mocks';2import { TestBed } from '@angular/core/testing';3import { MyComponent } from './my.component';4describe('MyComponent', () => {5 beforeEach(() => TestBed.configureTestingModule({ declarations: [MyComponent] }));6 it('should render', () => {7 const fixture = TestBed.createComponent(MyComponent);8 fixture.detectChanges();9 const element = fixture.nativeElement;10 expect(element).toMatchSnapshot();11 });12 it('should render with actual1', () => {13 const fixture = TestBed.createComponent(MyComponent);14 fixture.detectChanges();15 const element = fixture.nativeElement;16 expect(actual1(element)).toMatchSnapshot();17 });18});
Using AI Code Generation
1let actual1 = ngMocks.findInstance(Actual1);2let actual2 = ngMocks.findInstance(Actual2);3let actual1 = ngMocks.findInstance(Actual1);4let actual2 = ngMocks.findInstance(Actual2);5ngMocks.findInstance(Actual1);6ngMocks.findInstance(Actual2);7let actual1 = ngMocks.findInstance(Actual1);8let actual2 = ngMocks.findInstance(Actual2);9let actual1 = ngMocks.findInstance(Actual1);10let actual2 = ngMocks.findInstance(Actual2);11ngMocks.findInstance(Actual1);12ngMocks.findInstance(Actual2);13let actual1 = ngMocks.findInstance(Actual1);14let actual2 = ngMocks.findInstance(Actual2);15let actual1 = ngMocks.findInstance(Actual1);16let actual2 = ngMocks.findInstance(Actual2);17ngMocks.findInstance(Actual1);18ngMocks.findInstance(Actual2);19let actual1 = ngMocks.findInstance(Actual1);
Using AI Code Generation
1import { actual1 } from 'ng-mocks';2describe('test', () => {3 it('test', () => {4 const actual = actual1('test');5 expect(actual).toBe('test');6 });7});8import { actual1 } from 'ng-mocks';9describe('test', () => {10 it('test', () => {11 const actual = actual1('test');12 expect(actual).toBe('test');13 });14});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!