Last active
March 19, 2019 18:00
-
-
Save antoinejaussoin/6ae225bc95b624ae27ac20280820c51c to your computer and use it in GitHub Desktop.
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
import init from 'jooks'; | |
describe('Testing a custom hook', () => { | |
const jooks = init(() => useLoadActivity()); | |
it('Should load activities properly', async () => { | |
// By default, before it has a change to load anything, the hook | |
// will return a null | |
let result = jooks.run(); | |
expect(result.activity).toBeNull(); | |
// Then we wait for the component to "mount", essentially giving | |
// it time to resolve the effect and load the data | |
await jooks.mount(); | |
result = jooks.run(); // We run the hook again to update the result | |
expect(result.activity).not.toBeNull(); | |
expect(result.activity!.activity).toBe('Foo'); | |
// Then we call the next() callback | |
await result.next(); | |
result = jooks.run(); // We run the hook again to update the result | |
expect(result.activity).not.toBeNull(); | |
expect(result.activity!.activity).toBe('Bar'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment