Skip to content

Instantly share code, notes, and snippets.

@antoinejaussoin
Last active March 19, 2019 18:00
Show Gist options
  • Save antoinejaussoin/6ae225bc95b624ae27ac20280820c51c to your computer and use it in GitHub Desktop.
Save antoinejaussoin/6ae225bc95b624ae27ac20280820c51c to your computer and use it in GitHub Desktop.
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