|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import {CommonModule} from '@angular/common'; |
10 | | -import {Component, createEnvironmentInjector, Directive, EnvironmentInjector, forwardRef, Injector, Input, NgModule, NO_ERRORS_SCHEMA, OnInit, Pipe, PipeTransform, ViewChild, ViewContainerRef} from '@angular/core'; |
| 10 | +import {Component, createEnvironmentInjector, Directive, EnvironmentInjector, forwardRef, Injector, Input, isStandalone, NgModule, NO_ERRORS_SCHEMA, OnInit, Pipe, PipeTransform, ViewChild, ViewContainerRef} from '@angular/core'; |
11 | 11 | import {TestBed} from '@angular/core/testing'; |
12 | 12 |
|
13 | 13 | describe('standalone components, directives, and pipes', () => { |
@@ -847,4 +847,68 @@ describe('standalone components, directives, and pipes', () => { |
847 | 847 | expect(fixture.nativeElement.textContent).toBe(''); |
848 | 848 | }); |
849 | 849 | }); |
| 850 | + |
| 851 | + describe('isStandalone()', () => { |
| 852 | + it('should return `true` if component is standalone', () => { |
| 853 | + @Component({selector: 'standalone-cmp', standalone: true}) |
| 854 | + class StandaloneCmp { |
| 855 | + } |
| 856 | + |
| 857 | + expect(isStandalone(StandaloneCmp)).toBeTrue(); |
| 858 | + }); |
| 859 | + |
| 860 | + it('should return `false` if component is not standalone', () => { |
| 861 | + @Component({selector: 'standalone-cmp', standalone: false}) |
| 862 | + class StandaloneCmp { |
| 863 | + } |
| 864 | + |
| 865 | + expect(isStandalone(StandaloneCmp)).toBeFalse(); |
| 866 | + }); |
| 867 | + |
| 868 | + it('should return `true` if directive is standalone', () => { |
| 869 | + @Directive({selector: '[standaloneDir]', standalone: true}) |
| 870 | + class StandAloneDirective { |
| 871 | + } |
| 872 | + |
| 873 | + expect(isStandalone(StandAloneDirective)).toBeTrue(); |
| 874 | + }); |
| 875 | + |
| 876 | + it('should return `false` if directive is standalone', () => { |
| 877 | + @Directive({selector: '[standaloneDir]', standalone: false}) |
| 878 | + class StandAloneDirective { |
| 879 | + } |
| 880 | + |
| 881 | + expect(isStandalone(StandAloneDirective)).toBeFalse(); |
| 882 | + }); |
| 883 | + |
| 884 | + it('should return `true` if pipe is standalone', () => { |
| 885 | + @Pipe({name: 'standalonePipe', standalone: true}) |
| 886 | + class StandAlonePipe { |
| 887 | + } |
| 888 | + |
| 889 | + expect(isStandalone(StandAlonePipe)).toBeTrue(); |
| 890 | + }); |
| 891 | + |
| 892 | + it('should return `false` if pipe is standalone', () => { |
| 893 | + @Pipe({name: 'standalonePipe', standalone: false}) |
| 894 | + class StandAlonePipe { |
| 895 | + } |
| 896 | + |
| 897 | + expect(isStandalone(StandAlonePipe)).toBeFalse(); |
| 898 | + }); |
| 899 | + |
| 900 | + it('should return `false` if the class is not annotated', () => { |
| 901 | + class NonAnnotatedClass {} |
| 902 | + |
| 903 | + expect(isStandalone(NonAnnotatedClass)).toBeFalse(); |
| 904 | + }); |
| 905 | + |
| 906 | + it('should return `false` if the class is an NgModule', () => { |
| 907 | + @NgModule({}) |
| 908 | + class Module { |
| 909 | + } |
| 910 | + |
| 911 | + expect(isStandalone(Module)).toBeFalse(); |
| 912 | + }); |
| 913 | + }); |
850 | 914 | }); |
0 commit comments