Build and test
Create a production build, budgets and a component test.
What you will be able to do
- Run ng build before every release.
- Watch the bundle budgets.
- Test components through the DOM.
- Mock HTTP with provideHttpClientTesting.
In plain English
ng build compiles an optimized bundle and enforces size budgets. Tests use the Angular testing utilities with a TestBed. Keep tests focused on behaviour: render, interact, assert what the user sees.
import { TestBed } from '@angular/core/testing'
import { LessonCardComponent } from './lesson-card.component'
it('renders the title', () => {
TestBed.configureTestingModule({ imports: [LessonCardComponent] })
const fixture = TestBed.createComponent(LessonCardComponent)
fixture.componentRef.setInput('title', 'CSS Grid')
fixture.detectChanges()
expect(fixture.nativeElement.textContent).toContain('CSS Grid')
})Your turn
EasyRun the build
Write the command that builds an Angular app for production.
BASH · starter
ngCheck your understanding before moving on.
Knowledge checkQuestion 1
Which command creates an optimized production build?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.