- );
+const Timeout = ({delay, recurring}) => {
+ const {start, stop} = useTimeout(() => { spy += 1 }, delay, recurring);
+ start();
+ stopSpy = stop;
+ return null;
};
describe('useTimeout()', () => {
- it('Should return the previous value', async () => {
+ beforeEach(() => {
+ spy = 1;
+ });
+
+ it('Should execute the timeout callback once, when no other prameters specified', async () => {
+ await act(async () => {
+ const wrapper = mount(
);
+
+ expect(spy).toEqual(1);
+
+ await waitFor(0); // make sure the timeout has had enough time to fire
+ wrapper.update();
+ expect(spy).toEqual(2);
+ });
+ });
+
+ it('Should execute the timeout callback once', async () => {
+ await act(async () => {
+ const DELAY = 100;
+ const wrapper = mount(
);
+
+ expect(spy).toEqual(1);
+
+ await waitFor(DELAY/2);
+
+ // should remain "1" as the timeout has yet to be executed
+ expect(spy).toEqual(1);
+
+ await waitFor(DELAY/2);
+
+ wrapper.update();
+ expect(spy).toEqual(2);
+ });
+ });
+
+ it('Should not be recurring by default (called only once)', async () => {
await act(async () => {
- const wrapper = mount();
- expect(wrapper.find('.first').length).toEqual(1);
- expect(wrapper.find('.second').length).toEqual(0);
- wrapper.find('.first').simulate('click');
+ const wrapper = await mount();
+
+ expect(spy).toEqual(1);
+
await waitFor(0);
wrapper.update();
- expect(wrapper.find('.first').length).toEqual(0);
- expect(wrapper.find('.second').length).toEqual(1);
+ expect(spy).toEqual(2);
+
+ // wait some more time to make sure the timeout is not recurring
+ await waitFor(50);
+ wrapper.update();
+ expect(spy).toEqual(2);
+ });
+ });
+
+ it('Should stop recurring', async () => {
+ await act(async () => {
+ const DELAY = 50;
+ const wrapper = await mount();
+
+ expect(spy).toEqual(1);
+
+ await waitFor(DELAY * 3);
+ wrapper.update();
+ expect(spy).toEqual(3);
+
+ stopSpy();
+ await waitFor(DELAY * 2);
+ wrapper.update();
+ // should remain unchanged since last time
+ expect(spy).toEqual(3);
});
});
});
\ No newline at end of file
diff --git a/src/tools/Puppeteer/Puppeteer.test.js b/src/tools/Puppeteer/Puppeteer.test.js
index 11ccedf..aef236e 100644
--- a/src/tools/Puppeteer/Puppeteer.test.js
+++ b/src/tools/Puppeteer/Puppeteer.test.js
@@ -17,6 +17,7 @@ describe('Puppeteer', () => {
expect(wrapper.find('puppet()')).toHaveLength(1);
expect(wrapper.find('div').text()).toEqual('foobar');
});
+
it('should override the puppet\'s props based on namespace', () => {
const Container = ({children, value}) => (
{
expect(wrapper.find('.a').text()).toEqual('foobar');
expect(wrapper.find('.b').text()).toEqual('bar');
});
+
it('should override the puppet\'s props for global namespace', () => {
const Container = ({children, value}) => (
{
expect(wrapper.find('puppet()')).toHaveLength(1);
expect(wrapper.find('div').text()).toEqual('foobar');
});
+
it('should break the overriding of the puppet\'s props', () => {
const Container = ({children, value}) => (
{
wrapper.update();
expect(wrapper.find('div').text()).toEqual('bar');
});
+
+ it('should inherit props when nesting Puppeteered components', () => {
+ const Container = ({children, value}) => (
+ value + props.value}} namespace='hello'>{children}
+ );
+ const Puppet = puppet('hello')(({value}) => {value}
);
+ const wrapper = mount(
+
+
+
+
+
+ );
+
+ expect(wrapper.find('div').text()).toEqual('barfoobaz');
+ });
});