import React from 'react';
import Renderer from 'react-test-renderer';
import Coroutine from '../src/Coroutine';

describe('Coroutine', async () => {
  it('should render empty body until coroutine is resolved', async () => {
    const render = async () => <p>test</p>;
    const TestComponent = Coroutine.create(render);
    const tree = Renderer.create(<TestComponent />);

    const initial = Renderer.create(<noscript />);
    expect(tree.toJSON()).toEqual(initial.toJSON());

    const success = await Renderer.create(<p>test</p>);
    expect(tree.toJSON()).toEqual(success.toJSON());
  });

  it('should pass initial information', async () => {
    const render = async ({ number }) => <p>{ number }</p>;
    const variables = () => ({ number: 13 });
    const TestComponent = Coroutine.create(render, variables);
    const tree = Renderer.create(<TestComponent />);

    const success = await Renderer.create(<p>{13}</p>);
    expect(tree.toJSON()).toEqual(success.toJSON());
  });
});

@@ -980,13 +980,712 @@
 );%0A  %7D);
+%0A%0A  it('should re-render the component if variables are updated', async () =%3E %7B%0A    function getVariables() %7B%0A      return %7B number: 0 %7D;%0A    %7D%0A%0A    async function render(%7B number, forceUpdate %7D) %7B%0A      try %7B%0A        return %3Cp%3E%7B number %7D%3C/p%3E;%0A      %7D finally %7B%0A        await true;%0A        if (number === 0) forceUpdate(%7B number: 1 %7D);%0A      %7D%0A    %7D%0A%0A    const TestComponent = Coroutine.create(render, getVariables);%0A    const tree = await Renderer.create(%3CTestComponent /%3E);%0A%0A    const success = await Renderer.create(%3Cp%3E%7B0%7D%3C/p%3E);%0A    expect(tree.toJSON()).toEqual(success.toJSON());%0A%0A    const updated = await Renderer.create(%3Cp%3E%7B1%7D%3C/p%3E);%0A    expect(tree.toJSON()).toEqual(updated.toJSON());%0A  %7D);
 %0A%7D);%0A

implement test for forceUpdate