|
| 1 | +import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, viewChild } from '@angular/core'; |
| 2 | +import { TestBed } from '@angular/core/testing'; |
| 3 | +import { By } from '@angular/platform-browser'; |
| 4 | +import { NgtArgs } from 'angular-three'; |
| 5 | + |
| 6 | +describe('args', () => { |
| 7 | + it('should not render if first item is null', () => { |
| 8 | + const fixture = createTestFixture(`<div *args="[null]"></div>`); |
| 9 | + fixture.detectChanges(); |
| 10 | + |
| 11 | + expect(fixture.debugElement.queryAll(By.css('div')).length).toEqual(0); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should not render if args is null', () => { |
| 15 | + const fixture = createTestFixture(`<div *args="null"></div>`); |
| 16 | + fixture.detectChanges(); |
| 17 | + |
| 18 | + expect(fixture.debugElement.queryAll(By.css('div')).length).toEqual(0); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should not render if args is not an array', () => { |
| 22 | + const fixture = createTestFixture(`<div *args="1"></div>`); |
| 23 | + fixture.detectChanges(); |
| 24 | + |
| 25 | + expect(fixture.debugElement.queryAll(By.css('div')).length).toEqual(0); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should render if args is validated', () => { |
| 29 | + const fixture = createTestFixture(`<div *args="[1, 2, 3]"></div>`); |
| 30 | + fixture.detectChanges(); |
| 31 | + |
| 32 | + expect(fixture.debugElement.queryAll(By.css('div')).length).toEqual(1); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should only able to access value once ', () => { |
| 36 | + const fixture = createTestFixture(`<div *args="[1, 2, 3]"></div>`); |
| 37 | + fixture.detectChanges(); |
| 38 | + |
| 39 | + expect(fixture.debugElement.queryAll(By.css('div')).length).toEqual(1); |
| 40 | + const args = fixture.componentInstance.args(); |
| 41 | + expect(args!.value).toEqual([1, 2, 3]); |
| 42 | + expect(args!.value).toEqual(null); |
| 43 | + }); |
| 44 | +}); |
| 45 | + |
| 46 | +@Component({ |
| 47 | + standalone: true, |
| 48 | + template: '', |
| 49 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 50 | + imports: [NgtArgs], |
| 51 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 52 | +}) |
| 53 | +class Test { |
| 54 | + args = viewChild(NgtArgs); |
| 55 | +} |
| 56 | + |
| 57 | +function createTestFixture(template: string) { |
| 58 | + return TestBed.overrideComponent(Test, { set: { template } }).createComponent(Test); |
| 59 | +} |
0 commit comments