Angular·Angular from components to production

Build and test

Create a production build, budgets and a component test.

Intermediate 18 min read Lesson 10 of 300 Challenge included
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.

lesson-card.spec.tsTYPESCRIPT
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

Run the build

Easy

Write the command that builds an Angular app for production.

BASH · starter
ng
Check 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 in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 10 of 300 · 0% of course