Skip to content

Setting Up Jasmine and Karma / Jest

Angular applications include a testing environment by default.

Two popular setups:

ToolPurpose
JasmineTesting framework
KarmaTest runner
JestFaster alternative to Karma

Angular CLI usually installs Jasmine + Karma automatically.

Angular applications include a testing environment by default.

Two popular setups:

ToolPurpose
JasmineTesting framework
KarmaTest runner
JestFaster alternative to Karma

Angular CLI usually installs Jasmine + Karma automatically.

Terminal window
ng test

This command:

  • builds the test environment
  • launches Karma
  • runs all *.spec.ts files
Terminal window
npm install jest jest-preset-angular @types/jest
describe("Simple Test", () => {
it("should add numbers correctly", () => {
const result = 2 + 3;
expect(result).toBe(5);
});
});

Key concepts:

  • describe() defines a test suite
  • it() defines a test case
  • expect() verifies results

ng test This command:

  • builds the test environment
  • launches Karma
  • runs all *.spec.ts files
Terminal window
npm install jest jest-preset-angular @types/jest
describe("Simple Test", () => {
it("should add numbers correctly", () => {
const result = 2 + 3;
expect(result).toBe(5);
});
});

Key concepts:

  • describe() defines a test suite
  • it() defines a test case
  • expect() verifies results