“JEST MockName Mockname” Respostas de código

Método de zombaria por nome pelo nome

import Foo from './Foo';
import Bar from './Bar';

jest.mock('./Bar');

describe('Foo', () => {
  it('should return correct foo', () => {
    // As Bar is already mocked,
    // we just need to cast it to jest.Mock (for TypeScript) and mock whatever you want
    (Bar.prototype.runBar as jest.Mock).mockReturnValue('Mocked bar');
    const foo = new Foo();
    expect(foo.runFoo()).toBe('real foo : Mocked bar');
  });
});


Tame Tapir

JEST MockName Mockname

test("mockName", () => {
  const mockFn = jest.fn().mockName("mockedFunction");
  mockFn(); // comment me
  expect(mockFn).toHaveBeenCalled();
});
Restu Wahyu Saputra

Respostas semelhantes a “JEST MockName Mockname”

Perguntas semelhantes a “JEST MockName Mockname”

Procure respostas de código populares por idioma

Procurar outros idiomas de código