Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 1.16 KB

File metadata and controls

28 lines (19 loc) · 1.16 KB

Jest

Jest is a popular alternative to Karma + Jasmine. If you use Nrwl Nx, you can get it by default (but can choose Karma if you wish).

The syntax is very similar to Jasmine - more than 50% is exactly the same. If you know Jasmine, you'll immediately understand this:

it("#getValue should return value", () => {
  const spy = jest.spyOn(someService, "getValue");
  spy.mockReturnValue("stub value");

  expect(service.getValue()).toBe("stub value");
  expect(spy).toHaveBeenCalled();
});

The bit where Jest really shines ahead of Jasmine (apart from speed) is Snapshot Testing. See this article for an intro to Snapshot Testing

Links

Related