“Jest Mock Mockname” Kode Jawaban

Metode Mock Jest dengan Nama

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 Mock Mockname

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

Jawaban yang mirip dengan “Jest Mock Mockname”

Pertanyaan yang mirip dengan “Jest Mock Mockname”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya