Angular Web Framework Angular Quality & Compliance 3 — Questions and Answers
Question 1: What Angular CLI flag enforces strict template type checking during compilation?
- --strict-templates
- --template-strict
- --strict (Correct answer)
- --full-template-typecheck
Correct answer: --strict
The `--strict` flag (or `strict: true` in `tsconfig.json`) enables strict template type checking among other TypeScript strict settings.
Question 2: Which tool does Angular use internally to enforce coding style and detect anti-patterns via static analysis?
- JSHint
- Prettier
- ESLint with @angular-eslint rules (Correct answer)
- SonarQube
Correct answer: ESLint with @angular-eslint rules
Angular projects use ESLint extended with `@angular-eslint` rules to enforce Angular-specific coding conventions and detect anti-patterns.
Question 3: When writing an Angular component test, what does `TestBed.createComponent(MyComponent)` return?
- The component instance directly
- A ComponentFixture wrapping the component (Correct answer)
- A DebugElement of the host
- An Observable of the component lifecycle
Correct answer: A ComponentFixture wrapping the component
`createComponent()` returns a `ComponentFixture<T>` that provides access to the component instance, the native element, and change detection utilities.
Question 4: What is the role of `fakeAsync` and `tick()` in Angular unit tests?
- They replace Zone.js with a synchronous scheduler for testing async code (Correct answer)
- They stub all HTTP calls to resolve immediately
- They disable the Angular event loop during tests
- They spy on setTimeout and setInterval globally
Correct answer: They replace Zone.js with a synchronous scheduler for testing async code
`fakeAsync` creates a controlled synchronous zone where `tick()` advances the virtual clock, making asynchronous operations like timers and promises testable synchronously.
Question 5: Which Angular security context prevents Cross-Site Scripting when binding dynamic HTML content?
- SafeHtml pipe applied to the binding
- DomSanitizer.bypassSecurityTrustHtml() for all bindings
- Angular's built-in sanitization on [innerHTML] bindings (Correct answer)
- Content Security Policy meta tag only
Correct answer: Angular's built-in sanitization on [innerHTML] bindings
Angular automatically sanitizes values bound to `[innerHTML]` to strip dangerous HTML, preventing XSS without additional developer effort in most cases.
Question 6: What is the purpose of `ng lint --fix` in an Angular project?
- Automatically upgrades Angular to the latest version
- Applies auto-fixable ESLint rule corrections to source files (Correct answer)
- Rebuilds the project with linting errors treated as warnings
- Generates a lint report without modifying files
Correct answer: Applies auto-fixable ESLint rule corrections to source files
`ng lint --fix` passes the `--fix` flag to ESLint, which automatically corrects rule violations that have safe automated fixes.
Question 7: In Angular testing, what is the difference between `async` (from `@angular/core/testing`) and native `async/await`?
- Angular's `async` wraps the test in a zone that tracks all asynchronous operations before completing (Correct answer)
- Angular's `async` only works with Promises, not Observables
- Native async/await cannot be used in Jasmine tests at all
- There is no difference; they are interchangeable
Correct answer: Angular's `async` wraps the test in a zone that tracks all asynchronous operations before completing
Angular's `waitForAsync` (formerly `async`) runs the test inside an Angular zone that waits for all pending async tasks (Promises, XHR, timers) to complete before finishing.
What Angular CLI flag enforces strict template type checking during compilation?