What did you expect to happen? I expect that sinon.fakeServer.requests count was more that 1
What actually happens sinon.fakeServer.requests always is null
How to reproduce
describe('--Pictures Selector--', () => {
let server, store, wrap;
beforeEach(() => {
server = sinon.fakeServer.create();
server.respondWith("GET", /\/api\/users/, [
200, {"Content-Type":"application/json"}, JSON.stringify(mock_pictures_list_store)
]);
store = new Pictures_List_Store([]);
wrap = mount(
<Selectable_Picture_List store={store} />
);
axios.get('http://localhost:9157/api/users/5/images/30/0');
console.log("%c server.requests", "color: #C78B41", server.requests);
});
afterEach(() => {
server.restore();
});
it('render drop zone', () => {
server.respond();
console.log("%c server.requests", "color: #C78B41", server.requests);
expect(wrap.find('Dropzone')).to.have.length(1);
});
});
I call
axios.get
requests directly in test code and also it is called in componentWillMount
method of a react.js component
axios.get()
is asynchronous. This means that when your console.log
line runs, the xmlhttprequest
has not been created yet.
Thanks for the answer. But in the case when I use server.autoRespond = true;
or server.respondImmediately = true;
or server.respond();
server.requests is still empty. Is it right that those things don't work?
Is there any way to launch HTML testing with fakeServer ?
Is there any way to launch HTML testing with fakeServer ?
Yes, there is.
The solution to seeing the requests in your beforeEach
above is two-fold:
beforeEach
functionconsole.log
The changes would look like:
beforeEach(done => {
// ...
axios.get(...);
setTimeout(() => {
console.log("%c server.requests", "color: #C78B41", server.requests);
done();
});
});
Wow. That's works! Thanks. Finally, I got the way to build required tests.
Most helpful comment
Yes, there is.
The solution to seeing the requests in your
beforeEach
above is two-fold:beforeEach
functionconsole.log
The changes would look like: