mercredi 27 février 2019

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.

Aucun commentaire:

Enregistrer un commentaire