Specs got stuck in the end
See original GitHub issueI’m using superagent-mock
to mock my requests and, even returning the correct result and the tests are passing, after all specs are done, the suite got stuck and release after 60s (probably a timeout).
Disabling superagent-mock
makes all the specs to pass (hitting the real server), and the suite finishes instantly.
Below is my spec:
describe('search triggers', () => {
const mockObj = superagentMock(request, rules)
describe('city search', () => {
beforeEach(() => triggerSearchByCity())
it('should update the state', () => {
expect(subject.state.loaded).toEqual(true)
expect(subject.state.data).toEqual(apiMocks.cityResponse)
})
})
And my mock setup rules:
rules= [{
pattern: 'http://api.openweathermap.org/data/2.5/weather(.*)',
fixtures: function (match, params, headers, context) {
// City search mock
if (match[1] === '?q=Berlin%2CDE&units=metric&APPID=[MY APP ID]') {
return cityResponse
}
get: function (match, data) {
return {
body: data
};
}
}
];
And my superagent call:
return new Promise((resolve, reject) => {
request
.get('http://api.openweathermap.org/data/2.5/weather')
.query({
q: `Berlin,DE`,
units: 'metric',
APPID: '[My APP ID]'
})
.end((err, res) => {
if (err) { reject (err) }
else { resolve(res.body) }
})
})
The promise above is resolved in the triggerSearchByCity()
method.
UPDATE: Here’s another simpler setup that causes the same problem: https://gist.github.com/mauricioklein/b0dd5768bce0075232729596dc71a83f
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Specs got stuck in the end · Issue #69 - GitHub
I'm using superagent-mock to mock my requests and, even returning the correct result and the tests are passing, after all specs are done, ......
Read more >How to Remove A Speck From Your Eye: 7 Simple Tips
1. Make your eye water. When there is a speck in your eye, the best and most natural way to get a speck...
Read more >What Should I Do If Something Is Stuck In My Eye
The first thing to remember when something gets into your eye is to not rub your eye. That's because rubbing may lead to...
Read more >Why does my hair get stuck on my glasses end piece ... - Quora
Heat the temples under hot water or a hair dryer and bend them yourself - If you don't know what type of plastic...
Read more >Cocoapods setup stuck on pod setup command on terminal
So I checked the size of ~/.cocoapods directory to ensure it was still cloning. The size has increased to ~100Mb in the end....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same issue, and switched to superagent-mocker, which handles superagent’s RequestBase::then() correctly. Tests that hung Mocha with
superagent-mock
, no longer hung when usingsuperagent-mocker
(tests stayed exactly the same, only the before/after hooks were modified to use the other mocking library).@fdubost not sure why issue is closed. it’s still happening.
i’ve pinpointed to this particular moment https://github.com/M6Web/superagent-mock/blob/master/src/superagent-mock.js#L237-L242 where the setTimeout is never called ; but not sure why. It’d be great to fix it.