Jasmine vs Jest

Reading time ~1 minute

Jest

Соответствия matcher’ов в Jasmine и Jest

  • and.callThrough() –> mockImplementation()
  • and.callFake() –> mockImplementation()
  • and.returnValue() –> mockReturnValue()
  • and.spyOnProperty() –> spyOn()
  • and.toHaveBeenCalledOnceWith() –> toHaveBeenCalledTimes(1)
  • spyOn(…).and.callFake(() => {}) –> jest.spyOn(…).mockImplementation(() => {})
  • jasmine.createSpy(‘name’) –> jest.fn()
  • toBeTrue –> toBe(true)
  • toBeFalse –> toBe(false)

toHaveBeenCalled() - это алиас для toBeCalled()

Jasmine createSpyObj в Jest

В Jasmine объект шпиона создается, используя функцию createSpyObj и передавая в него параметры имени класса и массива методов:

const serviceMock = createSpyObj('service', ['method_1', 'method_2', 'method_3', 'method_4', 'method_5']);

В Jest просто создается объект с ожидаемыми свойствами, а функция jest.fn() создает методы-шпионы:

const serviceMock = {
    method_1: jest.fn(),
    method_2: jest.fn(),
    method_3: jest.fn(),
    method_4: jest.fn(),
    method_5: jest.fn()
};

Ссылки

Ошибка с версией Node.js

Довольно часто в своей практике сталкиваюсь с такой ошибкой, когда запускаю локально сторонний проект:```bash$ npm run start> dom-moving-...… Continue reading

Mangling Angular

Published on February 15, 2024

Constructor parameter without access modifier

Published on February 04, 2024