test hangs forever when asserting a response from an axios request.
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);
});
});
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.
Copy the relevant section from package.json:
{
"dependencies": {
"axios": "^0.15.3",
"bluebird": "^3.4.7",
},
"devDependencies": {
"ava": "^0.18.1",
}
}
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
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
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.
Most helpful comment
@RickyMarou a new version of
@ava/pretty-formatis out with a fix. I think if you donpm --depth 2 updateit should pull it in.