Skip to content

Commit

Permalink
fix tests correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
maapteh committed Nov 24, 2019
1 parent c4f039d commit 81fea98
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions src/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import ReactDOMServer from "react-dom/server";
import { render, cleanup } from '@testing-library/react';
import NoSSR from './';

// not good tests for ssr state...
describe('NoSSR Component', () => {
describe('without loading state', () => {

describe('on Client Side', () => {
afterEach(() => {
cleanup();
});
Expand All @@ -14,35 +15,30 @@ describe('NoSSR Component', () => {
<MyComp />
</NoSSR>
);
const { queryAllByText } = render(wrapper);
const { queryByText } = render(wrapper);

it('should render correctly', () => {
// TODO: add ssr state of default empty span
expect(queryAllByText(/Hello/)).toBeDefined();
it('should render correctly its inner component', () => {
queryByText(/Hello/);
});
});

describe('with loading state', () => {
afterEach(() => {
cleanup();
});
describe('on Server Side', () => {

const MyComp = () => <div>Hello</div>;
const Loading = () => <div>Loading...</div>;
const wrapper = (
<NoSSR onSSR={<Loading />}>
<MyComp />
</NoSSR>
);
const { queryByText, unmount, rerender } = render(wrapper);

it('Should render correctly', () => {
unmount();
expect(queryByText(/Hello/)).toBeNull();
expect(queryByText(/Loading/)).toBeDefined();
it('should render correctly with custom loading', () => {
const markup = ReactDOMServer.renderToStaticMarkup(<NoSSR onSSR={<Loading />}>
<MyComp />
</NoSSR>);
expect(markup).toBe('<div>Loading...</div>')
});

rerender(wrapper);
expect(queryByText(/Hello/)).toBeDefined();
expect(queryByText(/Loading/)).toBeNull();
it('should render correctly with no custom loading', () => {
const markup = ReactDOMServer.renderToStaticMarkup(<NoSSR>
<MyComp />
</NoSSR>);
expect(markup).toBe('')
});
});
});

0 comments on commit 81fea98

Please sign in to comment.