Angular › Testing with Jasmine & Karma
What are Jasmine and Karma, and what role does each play in testing an Angular app?
BeginnerAnswer
Jasmine is a testing framework that provides the actual syntax for writing tests, like describe and it blocks and expect assertions. Karma is a test runner that executes those tests in a real browser and reports the results, and both are set up automatically when you create a new Angular project with the CLI.
describe('Calculator', () => {
it('adds two numbers correctly', () => {
expect(add(2, 3)).toBe(5);
});
});
// Run with: ng testReal-world example A team writes a simple Jasmine test verifying their calculator function adds numbers correctly, and Karma automatically runs it in a real Chrome browser every time they execute ng test.