Last active
November 17, 2017 18:41
-
-
Save melloc01/b53af9c550911b9cb1e8239434284c2d to your computer and use it in GitHub Desktop.
Testando método async numa flux store com jest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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