4
respostas

[Bug] Eu testei a primeira vez e deu certo e agora aparece esse bug

describe('Api Alurapic', () => {
    it('Dados da API', () => {
           cy.request({
                method: 'POST',
                url: 'http://localhost:3000/user/login',
                failOnStatusCode: false,
                body: Cypress.env()
            }).then((res) => {
                expect(res.status).to.be.equal(200)
                expect(res.body).is.not.empty
                expect(res.body).to.have.property('id')
                expect(res.body.id).to.be.equal(3)
           })
    })
})

Mensagem que aparece:

Unexpected to be equal 401

4 respostas

Olá, tente rodar novamente o projeto do AluraPic, pois esse tipo de status code indica um que o usuário não tem permissão para acessar determinado recurso ou página.

Fico no aguardo.

Bom dia, ainda com a mensagem:

AssertionError: expected 401 to equal 200

Bom dia.

  • Acesse a aplicação do alurapic e digite o comando no terminal: npm start
  • Verifique se a aplicação está funcionando.
  • Rode o cypress novamente com o npx cypress open

Rodando certinho, eu tenho 8 testes rodando corretamente no mento e apenas esse persiste com a mensagem AssertionError: expected 401 to equal 200


> alurapic@0.0.0 start
> concurrently --kill-others "node api/server.js" "ng serve"

[0] node:events:368
[0]       throw er; // Unhandled 'error' event
[0]       ^
[0]
[0] Error: listen EADDRINUSE: address already in use :::3000
[0]     at Server.setupListenHandle [as _listen2] (node:net:1334:16)
[0]     at listenInCluster (node:net:1382:12)
[0]     at Server.listen (node:net:1469:7)
[0]     at Object.<anonymous> (C:\Users\maril\Desktop\alura\cypress curso\alurapic\api\server.js:4:24)
[0]     at Module._compile (node:internal/modules/cjs/loader:1101:14)
[0]     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
[0]     at Module.load (node:internal/modules/cjs/loader:981:32)
[0]     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
[0]     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
[0]     at node:internal/main/run_main_module:17:47
[0] Emitted 'error' event on Server instance at:
[0]     at emitErrorNT (node:net:1361:8)
[0]     at processTicksAndRejections (node:internal/process/task_queues:83:21) {
[0]   code: 'EADDRINUSE',
[0]   errno: -4091,
[0]   syscall: 'listen',
[0]   address: '::',
[0]   port: 3000
[0] }
[0] node api/server.js exited with code 1
--> Sending SIGTERM to other processes..
[1] ng serve exited with code 1
PS C:\Users\maril\Desktop\alura\cypress curso\alurapic> npm start

> alurapic@0.0.0 start
> concurrently --kill-others "node api/server.js" "ng serve"

[0] Servidor escutando na porta: 3000
[0] Users
[0] {
[0]   user_id: 1,
[0]   user_name: 'flavio',
[0]   user_email: 'flavio@alurapic.com.br',
[0]   user_password: 123,
[0]   user_full_name: 'Flávio',
[0]   user_join_date: '2023-04-10 18:03:41'
[0] }
[0] Users
[0] {
[0]   user_id: 2,
[0]   user_name: 'almeida',
[0]   user_email: 'almeida@alurapic.com.br',
[0]   user_password: 123,
[0]   user_full_name: 'Almeida',
[0]   user_join_date: '2023-04-10 18:03:41'
[0] }
[0] Users
[0] {
[0]   user_id: 3,
[0]   user_name: 'catarinamm',
[0]   user_email: 'catarina@gmail.com',
[0]   user_password: 'catarina000',
[0]   user_full_name: 'Catarina Maria',
[0]   user_join_date: 1710334276332
[0] }

[1] (node:4584) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated.
[1] (Use `node --trace-deprecation ...` to show where the warning was created)
[1] ** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

//código omitido