Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何让command.js和index.d.ts知道该函数?_Reactjs_Cypress_Autotest - Fatal编程技术网

Reactjs 如何让command.js和index.d.ts知道该函数?

Reactjs 如何让command.js和index.d.ts知道该函数?,reactjs,cypress,autotest,Reactjs,Cypress,Autotest,我在Cypress中得到了这个测试,问题是它不会向Cypress.commands.add传递任何值 Commands.js: Cypress.Commands.add('createCustomer', (customer) => { cy.wait(1000) cy.get('input[name="id"]').clear() cy.get('input[name="id"]').type(customer.cust_i

我在Cypress中得到了这个测试,问题是它不会向Cypress.commands.add传递任何值

Commands.js:

Cypress.Commands.add('createCustomer', (customer) => {
    cy.wait(1000)
    cy.get('input[name="id"]').clear()
    cy.get('input[name="id"]').type(customer.cust_id)
    cy.wait(1000)
    cy.get('input[name="name"]').clear().type(customer.name);
})
索引d.ts:

declare namespace Cypress {
    interface Chainable<Subject> {
        createCustomer(
            cust_id: string,
            name: string): Chainable<string>
    }
}
test.spec.ts似乎没有将值传递给commands.js


请帮忙。谢谢…

您正在测试客户id和客户名称中传递两个参数,因此您的自定义命令应该如下所示:

Cypress.Commands.add('createCustomer', (id, name) => {
    cy.wait(1000)
    cy.get('input[name="id"]').clear()
    cy.get('input[name="id"]').type(id)
    cy.wait(1000)
    cy.get('input[name="name"]').clear().type(name);
})
Cypress.Commands.add('createCustomer', (id, name) => {
    cy.wait(1000)
    cy.get('input[name="id"]').clear()
    cy.get('input[name="id"]').type(id)
    cy.wait(1000)
    cy.get('input[name="name"]').clear().type(name);
})