Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

async call with React/Redux/Axios fails #1191

Open
lucasstarick opened this issue Mar 14, 2019 · 0 comments
Open

async call with React/Redux/Axios fails #1191

lucasstarick opened this issue Mar 14, 2019 · 0 comments

Comments

@lucasstarick
Copy link

lucasstarick commented Mar 14, 2019

I am trying to implement a test with zombie version 6.1.4 in a react js application.

The application at the time of login makes a request for an external API through the axios and if the login is ok the user is redirected to the administrative area.

My test is failing when the user is invalid and the API returns me the status of the 401 request.

H:\newVersionProject\mi-web-frontend\node_modules\react-scripts\scripts\test.js:20
  throw err;
  ^
StatusCodeError: 401 - "{\n    \"message\": \"Invalid credentials\"\n}\n"
    at new StatusCodeError (H:\newVersionProject\mi-web-frontend\node_modules\request-promise-core\lib\errors.js:32:15)
    at Request.plumbing.callback (H:\newVersionProject\mi-web-frontend\node_modules\request-promise-core\lib\plumbing.js:104:33)
    at Request.RP$callback [as _callback] (H:\newVersionProject\mi-web-frontend\node_modules\request-promise-core\lib\plumbing.js:46:31)
    at Request.self.callback (H:\newVersionProject\mi-web-frontend\node_modules\request\request.js:185:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (H:\newVersionProject\mi-web-frontend\node_modules\request\request.js:1161:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (H:\newVersionProject\mi-web-frontend\node_modules\request\request.js:1083:12)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
    at process._tickCallback (internal/process/next_tick.js:181:9)
npm ERR! Test failed.  See above for more details.

Below the test code:

/* eslint-disable */
const assert = require('assert');
const Browser = require('zombie');

describe('Funcionalidade de Autenticação', function () {
  var originalTimeout;

  originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
  jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;

  const browser = new Browser();

  describe('Acesso Usuário Inexistente', function () {
    it('Login', async function(){

      await browser.visit('http://localhost:3000/#/').
            then(() => browser.fill("input[name=email]", '[email protected]')).
            then(() => browser.fill('input[name=password]', '12345678')).
            then(() => browser.pressButton('Realizar Login'));
    });
  });

  afterAll(function () {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;

    browser.destroy();
  });
});

When the user exists the test works normally

Thank you

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant