After transitioning from using Cypress with Javascript specs to Typescript, I encountered a challenge in working with Fixtures. In Javascript, the approach below worked; however, I faced difficulties when switching to Typescript.
Fixture JSON file:
I store 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:
In the sample test below, I am utilizing the loaded fixture file,
it('Test something', () => {
cy.get('@sqlQueries')
.then((queries) => {
cy.log(queries.query_1)
})
})
Problem:
The error message received is
Property 'query_1' does not exist on type 'JQuery<HTMLElement>
Any assistance on this issue would be highly appreciated.