This blog represents techniques to setup unit testing environment for doing unit tests for Angular components with external template and CSS files. The blog is applicable for Angular 2/Angular 4/Angular 5 versions.
Using first technique, BeforeEach method is called for two times:
describe('SignupComponent', () => { let fixture: ComponentFixture<SignupComponent>; let component: SignupComponent; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ SignupComponent ], imports: [ FormsModule ], }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(SignupComponent); component = fixture.componentInstance; }); it('should create the app', async(() => { expect(component).toBeTruthy(); })); });
In this technique, the synchronous execution of code related with creation of components etc is moved with TestBed.compileComponents.then(…) callback method. Note that the compileComponents method returns a promise so you can perform additional tasks immediately after it finishes.
describe('SignupComponent', () => { let fixture: ComponentFixture<SignupComponent>; let component: SignupComponent; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ SignupComponent ], imports: [ FormsModule ], }).compileComponents().then(() => { fixture = TestBed.createComponent(SignupComponent); component = fixture.componentInstance; }); })); it('should create the app', async(() => { expect(component).toBeTruthy(); })); });
In case you are developing web apps using Spring and Angular, check out my book, Building web apps with Spring 5 and Angular. Grab your ebook today and get started.
Large language models (LLMs) have fundamentally transformed our digital landscape, powering everything from chatbots and…
As Large Language Models (LLMs) evolve into autonomous agents, understanding agentic workflow design patterns has…
In today's data-driven business landscape, organizations are constantly seeking ways to harness the power of…
In this blog, you would get to know the essential mathematical topics you need to…
This blog represents a list of questions you can ask when thinking like a product…
AI agents are autonomous systems combining three core components: a reasoning engine (powered by LLM),…