https://cypress.io logo
Syntax Error
# i-need-help
a
Hello guys, i having a trouble with my code, if a use twice JSON.parse() in my code, the second give me a Syntax error, someone can explain me why?
Copy code
it("Should verify status", () => {
    login(usuario.user);
    cy.visit("arp/");
    var status = JSON.parse(localStorage.getItem("@AXS-login") || "");
    var ultimo = status.Cards.pop();
    var state = JSON.stringify(ultimo.status_arp);
    console.log(state);
    cy.request({
      method: "POST",
      url: "https://dev-iris.axsenergia.com.br/csp/representante/login/",
      header: "Content-Type: application/json",
      header: "accept: application/json",
      body: {
        email: "versebank@teste.com",
        senha: "teste123",
      },
    }).then((response) => {
      expect(response.status).to.equal(200);
      expect(state).to.equal('"Aguardando Aceite"')
    });
  });

  it("After checks, exclude card", () => {
    cy.wait(2000);
    var card = JSON.parse(localStorage.getItem("@AXS-Energia:LastIdCard") || "");                     //<- on this guy
    cy.log("Card capturado: "+ card)
    cy.request({
      method: "POST",
      url: "https://api.pipefy.com/graphql",
      auth: {
        bearer:
          "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJ1c2VyIjp7ImlkIjozMDIwMTgxMDQsImVtYWlsIjoiaGVucmlxdWUuc2F2aUBicGx1cy5jb20uYnIiLCJhcHBsaWNhdGlvbiI6MzAwMjE0OTM4fX0.Wxt8GX-pVkEpuZSH4dIVKlNXsQJ38PW1SLTLCP0h9D9nsIwjBaqmJvQcHx4V0AweCBReRyUr8kpz6h6pRLSw4Q",
      },
      header: "Content-Type: application/json",
      header: "accept: application/json",
      body: {
        query:
          "mutation{   deleteCard(input:{id: " +
          card +
          "}) {     clientMutationId     success   }}",
      },
    }).then((response) => {
      expect(response.status).to.equal(200);
    });
    cy.log("Card deleted successfully")
  });
2 Views