Skip to content

Instantly share code, notes, and snippets.

@melloc01
Last active November 17, 2017 18:41
Show Gist options
  • Save melloc01/b53af9c550911b9cb1e8239434284c2d to your computer and use it in GitHub Desktop.
Save melloc01/b53af9c550911b9cb1e8239434284c2d to your computer and use it in GitHub Desktop.
Testando método async numa flux store com jest
// no test
const subscriber = require('./subscriber') // automock
it('should test something', () => {
dispatch(dispatcher, BLIR_CONSTANT, null, { requestIndex: 2 })
console.log('esse aparece antes')
// no teste, esse subscriber é o mesmo (===) lá dentro do escopo do src
expect(subscriber.request.mock.calls).toHaveLength(1)
})
// no source, que é um flux - store
const subscriber = function() {}
function f1() {
fetch(url).then(d => f2(d))
}
function f2(d) {
console.log('esse aparece depois')
subscriber.request()
}
// a store está testada seguindo esses guidelines:
// https://shripadk.github.io/react/blog/2014/09/24/testing-flux-applications.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment