Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage.uploadFile does not return UploadTask #177

Closed
eugenio1590 opened this issue Mar 22, 2019 · 3 comments
Closed

storage.uploadFile does not return UploadTask #177

eugenio1590 opened this issue Mar 22, 2019 · 3 comments

Comments

@eugenio1590
Copy link

I am calling the 'storage.uploadFile' function and I get an error when trying to subscribe to the event channel. This is because the function returns an 'UploadTaskSnapshot' object. This is my code:

const task = yield call(reduxSagaFirebase.storage.uploadFile, file.serverPath, file)
console.log(task)
const channel = eventChannel(emit => task.on('state_changed', emit))
yield takeEvery(channel, function* callback(snapshot) {
  console.log(snapshot)
})
yield task

The image is saved in Firebase but I am going to display the progress bar with the information of the snapshot but in the task.

"firebase": "^5.9.1",
"redux-saga-firebase": "^0.15.0",
@eugenio1590 eugenio1590 changed the title storage.uploadFile not return UploadTask storage.uploadFile does not return UploadTask Mar 22, 2019
@eugenio1590
Copy link
Author

I resolved it calling the function directly and wait for the task to finish at the bottom.

const task = reduxSagaFirebase.storage.uploadFile(file.serverPath, file)
const channel = eventChannel(emit => task.on('state_changed', emit))
yield takeEvery(channel, function* callback(snapshot) {
  console.log(snapshot)
})
yield task

It's important to update the documentation.

@n6g7
Copy link
Owner

n6g7 commented Mar 25, 2019

Hi there,

Thanks for the feedback!

Unfortunately that's a side effect of firebase.storage.UploadTask having a then method, so redux-saga assumes it's a promise and resolves it.

So, as far as I can tell, your solution is correct, even though you lose the ability to properly test your saga. That's actually exactly what I did in the example codebase to go around this issue.

I'll update the docs, thanks!

@n6g7 n6g7 reopened this Mar 25, 2019
@eugenio1590
Copy link
Author

Yes, the test is difficult to with this change. But using a manual mock with jest for returning the correct answer, It worked for me. Thanks to you.

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

No branches or pull requests

2 participants