Skip to content

Commit

Permalink
Refactoring some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-papsdorf committed Aug 7, 2020
1 parent c22073c commit 88eeaaf
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions app/src/components/ExplorationViews/MethodView/MethodView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { act } from 'react-dom/test-utils';
import { baseURL } from '../../../config/constants';
import MethodView from './MethodView';
import { cleanUpContainer, prepareContainer } from '../../../test-utils/test-helper';
import { getFetchMethodInfoAndCodeMock } from '../../../test-utils/apiMocks';
import {
getFetchMethodInfoAndCodeMock,
getSampleClassName,
getSampleMethodName,
getSampleSide
} from '../../../test-utils/apiMocks';

let container = null;

const className = 'className';
const site = 'site';
const methodName = 'methodName';
const path = `${baseURL}/env/classes/${className}/methods/${site}/${methodName}`;

beforeEach(() => {
jest.clearAllMocks();
// setup a DOM element as a render target
Expand All @@ -26,11 +26,20 @@ afterEach(() => {

describe('Method View', () => {
it('should display a current method', async () => {
const fetchMock = getFetchMethodInfoAndCodeMock(className, site, methodName);
const path = `${baseURL}/env/classes/${getSampleClassName()}/methods/${getSampleSide()}/${getSampleMethodName()}`;
const fetchMock = getFetchMethodInfoAndCodeMock(
getSampleClassName(),
getSampleSide(),
getSampleMethodName()
);

await act(async () => {
render(
<MethodView currentClass={className} site={site} currentMethod={methodName} />,
<MethodView
currentClass={getSampleClassName()}
site={getSampleSide()}
currentMethod={getSampleMethodName()}
/>,
container
);
});
Expand All @@ -39,7 +48,7 @@ describe('Method View', () => {

expect(fetchMock).toHaveBeenCalledWith(`${path}/text`);

expect(container.querySelector('h1')).toHaveTextContent(methodName);
expect(container.querySelector('h1')).toHaveTextContent(getSampleMethodName());

expect(container.querySelector('code')).toHaveTextContent(
'readFrom: aStream ^ self new readFrom: aStream.'
Expand Down

0 comments on commit 88eeaaf

Please sign in to comment.