Jest 的新手,尝试编写一个基本的测试用例来检查 Jest 中的下拉功能。
我试过下面的代码:
test( "update state with dropdown", async () => {
let wrapper = mount( <MemoryRouter initialEntries={[ “/workflow/new" ]}><Workflow/></MemoryRouter> );
expect.assertions( 7 );
// Mock validation API calls
let apiWorkflowPromise = Promise.resolve( apiWorkflowResult );
get.mockImplementation( () => apiWorkflowPromise );
// ACT
let instance = wrapper.find( “Workflow” ).instance();
instance.handleWorkflowDropDownChange( { target: { value: “NewZealand” } } );
await expect( apiWorkflowPromise ).resolves.toBeDefined();
// ASSERT
let selectedDiagnosticWorkflow = instance.state.selectedWorkflow;
let supportedParameters = instance.state.workflow.supportedParameters;
expect( selectedWorkflow ).toEqual( “NewZealand” );
} );
收到以下错误:
ReferenceError:事件未在 Workflow.handleWorkflowDropDownChange 中定义