简体   繁体   中英

Cypress fixtures usage in TypeScript

I have used Cypress with Javascript specs and recently switched to Typescript. While using Fixtures, I had the below approach working in Javascript; but, with Typescript I face some difficulty.

Fixture JSON file:

I have my fixture file in /cypress/fixtures/sql_queries.json

{
    "query_1": "SELECT * FROM TABLE_1",
    "query_2": "SELECT * FROM TABLE_2",
}

Before:

before('Load data to fixture', () => {
     cy.fixture('sql_queries')
         .as('sqlQueries')
})

Test spec:

I'm consuming the loaded fixture file in below sample test,

it('Test something', () => {
     cy.get('@sqlQueries')
         .then((queries) => {
             cy.log(queries.query_1)
         })
})

Problem:

I'm getting the error as Property 'query_1' does not exist on type 'JQuery<HTMLElement>

Any help would be appreciated.

类型定义似乎认为你的alias是一个元素。尝试在参数上添加一个类型到传递给.then的函数:

.then((queries:any) => {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM