Advertisement
Beginner Angular, Testing with Jasmine & Karma

What are Jasmine and Karma, and what role does each play in testing an Angular app?

Short answer

Jasmine is a testing framework that provides the actual syntax for writing tests, like describe and it blocks and expect assertions.

Save Angular mock interview
Advertisement
AModel answer
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 test
Real-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.
Likely follow-ups
  • How do you run tests just once instead of watching for changes continuously?
  • What is the difference between Jasmine's toBe and toEqual matchers?
Related topics