Skip to content

Commit

Permalink
Merge pull request #12 from streamich/fix-tests
Browse files Browse the repository at this point in the history
fix: πŸ› simplify AfterDraf component
  • Loading branch information
streamich committed Sep 30, 2018
2 parents 81f8fc1 + 5d71134 commit d34ac4f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 108 deletions.
3 changes: 0 additions & 3 deletions src/AfterDraf/__tests__/createSingleRunDraf.server.test.tsx

This file was deleted.

64 changes: 0 additions & 64 deletions src/AfterDraf/__tests__/createSingleRunDraf.test.tsx

This file was deleted.

15 changes: 14 additions & 1 deletion src/AfterDraf/__tests__/index.server.test.tsx
@@ -1,3 +1,16 @@
/** @jest-environment node */
import {createElement as h} from 'react';
import ReactDOMServer from 'react-dom/server';
import {AfterDraf} from '..';

require('./index.test');
const sleep = (time) => new Promise((resolve) => setTimeout(resolve, time));

describe('<AfterDraf>', () => {
it('Renders children', async () => {
const str = ReactDOMServer.renderToStaticMarkup(<AfterDraf>
<div>foobar</div>
</AfterDraf>);

expect(str).toBe('<div>foobar</div>');
});
});
49 changes: 9 additions & 40 deletions src/AfterDraf/__tests__/index.test.tsx
@@ -1,8 +1,7 @@
import {createElement as h} from 'react';
import {shallow} from 'enzyme';
import {render} from 'react-dom';
import {AfterDraf} from '..';

const isClient = typeof window === 'object';
const sleep = (time) => new Promise((resolve) => setTimeout(resolve, time));

describe('<AfterDraf>', () => {
Expand All @@ -11,50 +10,20 @@ describe('<AfterDraf>', () => {
});

it('waits for DRAF on client before rendering', async () => {
const wrapper = shallow(
<AfterDraf>
<div>foobar</div>
</AfterDraf>
);

if (isClient) {
expect(wrapper.html()).toBe(null);
} else {
expect(wrapper.html()).toBe('<div>foobar</div>');
}

await sleep(100);

wrapper.update();
const div = document.createElement('div');

expect(wrapper.html()).toBe('<div>foobar</div>');
});

it('waits for DRAF every mount', async () => {
shallow(
<AfterDraf>
document.body.appendChild(div);
render(<AfterDraf>
<div>foobar</div>
</AfterDraf>
);

await sleep(100);

const wrapper2 = shallow(
<AfterDraf>
<div>bazooka</div>
</AfterDraf>
);
</AfterDraf>,
div);

if (isClient) {
expect(wrapper2.html()).toBe(null);
} else {
expect(wrapper2.html()).toBe('<div>bazooka</div>');
}
expect(div.innerHTML).toBe('');

await sleep(100);

wrapper2.update();
expect(div.innerHTML).toBe('<div>foobar</div>');

expect(wrapper2.html()).toBe('<div>bazooka</div>');
document.body.removeChild(div);
});
});

1 comment on commit d34ac4f

@streamich
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build version: 2.0.1-master.71 🀞 master on Travis πŸŽ‰

Please sign in to comment.