Skip to content

Commit

Permalink
test: finish porting tests to testing-library
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Apr 15, 2022
1 parent 741f1d3 commit e6c809a
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 147 deletions.
23 changes: 0 additions & 23 deletions test-old/Then.test.tsx

This file was deleted.

62 changes: 0 additions & 62 deletions test-old/Unless.test.tsx

This file was deleted.

62 changes: 0 additions & 62 deletions test-old/When.test.tsx

This file was deleted.

15 changes: 15 additions & 0 deletions test/Then.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import { Then } from '../src';

describe('<Then /> component', () => {
test('GIVEN children THEN directly renders children', () => {
render(
<Then>
<span data-testid="thenChild">Then</span>
</Then>
);

expect(screen.getByTestId('thenChild')).toContainHTML('<span data-testid="thenChild">Then</span>');
});
});
49 changes: 49 additions & 0 deletions test/Unless.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import { Unless } from '../src';

describe('<Unless /> component', () => {
describe('Truthy cases', () => {
test('GIVEN some children THEN does not render those', () => {
render(
<Unless condition={true}>
<span data-testid="unlessChild">Unless</span>
</Unless>
);

expect(screen.queryByTestId('unlessChild')).toBeNull();
});

test('GIVEN condition as function & children THEN does not render those', () => {
render(
<Unless condition={() => true}>
<span data-testid="unlessChild">Unless</span>
</Unless>
);

expect(screen.queryByTestId('unlessChild')).toBeNull();
});
});

describe('Falsy cases', () => {
test('GIVEN some children THEN renders those', () => {
render(
<Unless condition={false}>
<span data-testid="unlessChild">Unless</span>
</Unless>
);

expect(screen.queryByTestId('unlessChild')).toContainHTML('<span data-testid="unlessChild">Unless</span>');
});

test('GIVEN condition as function & some children THEN renders those', () => {
render(
<Unless condition={() => false}>
<span data-testid="unlessChild">Unless</span>
</Unless>
);

expect(screen.queryByTestId('unlessChild')).toContainHTML('<span data-testid="unlessChild">Unless</span>');
});
});
});
49 changes: 49 additions & 0 deletions test/When.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { When } from '../src';

describe('<When /> component', () => {
describe('Truthy cases', () => {
test('GIVEN some children THEN renders those', () => {
render(
<When condition={true}>
<span data-testid="whenChild">When</span>
</When>
);

expect(screen.getByTestId('whenChild')).toContainHTML('<span data-testid="whenChild">When</span>');
});

test('GIVEN condition as function & children THEN renders those', () => {
render(
<When condition={() => true}>
<span data-testid="whenChild">When</span>
</When>
);

expect(screen.getByTestId('whenChild')).toContainHTML('<span data-testid="whenChild">When</span>');
});
});

describe('Falsy cases', () => {
test('GIVEN some children THEN does not render those', () => {
render(
<When condition={false}>
<span data-testid="whenChild">When</span>
</When>
);

expect(screen.queryByTestId('whenChild')).toBeNull();
});

test('GIVEN condition as function & some children THEN does not render those', () => {
render(
<When condition={() => false}>
<span data-testid="whenChild">When</span>
</When>
);

expect(screen.queryByTestId('whenChild')).toBeNull();
});
});
});

0 comments on commit e6c809a

Please sign in to comment.