Unit Test

How do I set the values for fields in antform if getFieldsValue is used in the code?

Solution: use setFieldsValue to set value for fields in antform

  test('import', (done: any) => {    const testComponent = createRemoteImportForm()    const form = testComponent.root.find(      (node: any) => (node.type as any).name === 'RemoteImportForm',    )    form.instance.props.form.setFieldsValue(getFieldsValueImport)    setImmediate(() => {      form.instance.handleImport()      moxios.wait(() => {        expect(form.instance.props.onClose.mock.calls.length).toBe(1)        done()      })    })  })

What is RDD and how do you write it?

A: RDD = readable driven development

Code:

describe("GIFW Table Test", () =>{      describe("Render the table", () =>{            it("Render Column A", () => {});            .....            it("Render Operation Actions", () => {});      });describe("Operate the Table", () =>{            it("Click Delete Button", () => {});            .....            it("Search Filter.", () => {});      });});

Where are the documents for End-to-End and unit testing?

Timeout issue on SubGlobalServerList.text.tsx?

In the function 'onUnAssociateSG', serviceGroup API is /hccapi/v3/provider/${getItem( 'PROVIDER',)}/tenant/${tenant}/shared-object/slb/service-group/${sgName}. Before testing the function, a provider name needs to be initialized. Otherwise, moxios API will not succeed, and a timeout error will be returned.

  test('should call onUnassociateSg in PortList.tsx work', async (done: any) => {
    ;(global as any).sessionStorage.setItem('PROVIDER', 'root')
    ;(global as any).sessionStorage.setItem('tenant', 'test')
    ;(global as any).sessionStorage.setItem('ALLTENANTS', '[{"name": "test"}]')
    mockGetServiceGroupResponse()
    mockPostServiceGroupResponse()
    const testComponent = renderPortList()
    const portListNode = testComponent.root.find(
      (node: any) => node.type.name === 'PortList',
    )
    await portListNode.instance.onUnAssociateSg(
      portListProps.data[0],
      'httpService1-80',
    )
    expect(testComponent.toJSON()).toMatchSnapshot()
    done()
  })

How do I test if the code has window.location.href?

1 Add a URL to the jest config

2 Use HTML5 history API

If you are using Redux state, ignoring A10Theme issue, and cannot run a10-gui-framework store procedure

1 createState

2 Use initState={state} in HCProvider to add data to Redux store

How do I prevent a 'Network Issue' error when running unit test code?

Use a try cacTh block for the source code.

How do I find your component in the customized form?

Solution: find it by name inside the moxios.wait function

1 add it into moxios.wait function

2 add it into setImmediate function

Last updated

Was this helpful?