Reputation: 1864
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.
Upvotes: 5
Views: 5945
Reputation: 18099
The type definitions seem to think your alias
was of an element.Try adding a type on the parameter to the function passed to .then
:
.then((queries:any) => {
Upvotes: 2