cy.wait("api").then((xhr: any) => {
expect(xhr.method).to.eq("POST");
expect(xhr.status).to.eq(200);
expect(xhr.requestBody.test).to.not.exist;
});
expect(xhr.requestBody.test).to.not.exist; this line throws eslint error as shown below:
error Expected an assignment or function call and instead saw an expression @typescript-eslint/no-unused-expressions
CodePudding user response:
In my opinion you have multiple options to solve this:
First and recommended option is to rewrite your assertion for example as follows:
const bodyContainsTest = xhr.requestBody.hasOwnProperty('test');
expect(bodyContainsTest).to.be.false;
Second option would be to simply disable that rule for the next line:
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
expect(xhr.requestBody.test).to.not.exist;
Another option would be to disable this rule globally for all Cypress test files in your .eslintrc.json
if needed:
"@typescript-eslint/no-unused-expressions": "off",
CodePudding user response:
Verified at tslint-playground.
Two alternates that pass the linter:
expect(xhr.requestBody).to.not.have.property(test)
expect(xhr.requestBody.test).to.eq(undefined)