Ava: test hangs forever when asserting a response from an axios request

Created on 14 Feb 2017  路  2Comments  路  Source: avajs/ava

Description

test hangs forever when asserting a response from an axios request.

Test Source

originally a typescript file :

import test from 'ava'
import axios from 'axios'

test('axios test', function (t) {
  return axios.get('https://www.google.de/search?q=help')
    .then((response) => {
      console.log(response.data)

      // DOES NOT EXIT
      t.true(response.data === 'something')

      // DOES EXIT
      const data = response.data
      t.true(data === 'something')

      // DOES EXIT
      const assert = response.data === 'something'
      t.true(assert)
    })
})

here is the compiled output, nothing suprising really :

"use strict";
const ava_1 = require("ava");
const axios_1 = require("axios");
ava_1.default('axios test', function (t) {
    return axios_1.default.get('https://www.google.de/search?q=help')
        .then((response) => {
        console.log(response.data.length);
        // DOES NOT EXIT
        t.true(response.data === 'something');
        // DOES EXIT
        const data = response.data;
        t.true(data === 'something');
        // DOES EXIT
        const assert = response.data === 'something';
        t.true(assert);
    });
});

Error Message & Stack Trace

There is no error message, the test just hangs forever. The test only hangs when the response is being asserted, if the response is assigned to a variable and this variable is being asserted, the test ends as expected.

Config

Copy the relevant section from package.json:

{
  "dependencies": {
    "axios": "^0.15.3",
    "bluebird": "^3.4.7",
  },
  "devDependencies": {
    "ava": "^0.18.1",
  }
}

Command-Line Arguments

I have build scripts but the error could be reproduced by running the test (from the transpiled js) with the ava CLI

ava -v tests/build/tests/axios.test.js

Environment

node :

Node.js v6.9.4
darwin 15.6.0

ava :

0.18.1

npm:

3.10.10

I hope this issue report will be useful :) keep up the good work

bug

Most helpful comment

@RickyMarou a new version of @ava/pretty-format is out with a fix. I think if you do npm --depth 2 update it should pull it in.

All 2 comments

With t.true(response.data === 'something'), power-assert will display the entire response object. This includes Node.js HTTP objects which are exposed by axios. These include symbol keys. Our version of pretty-format contains a bug which causes it to crash when it encounters a symbol key. I've opened a PR to fix that: https://github.com/avajs/pretty-format/pull/2

Unfortunately this crash gets lost in a promise chain, which causes the test to hang. https://github.com/avajs/ava/pull/1265 should deal with that.

Thanks for finding this!

@RickyMarou a new version of @ava/pretty-format is out with a fix. I think if you do npm --depth 2 update it should pull it in.

Was this page helpful?
0 / 5 - 0 ratings