Skip to content

Commit

Permalink
Improve scalar values support in FactValue
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed May 15, 2023
1 parent 1e65870 commit c7ec2a7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function FactValue({ className, data }) {
return typeof data === 'object' ? (
<ObjectTree className={className} data={data} />
) : (
<span className={className}>{data}</span>
<span className={className}>{`${data}`}</span>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { faker } from '@faker-js/faker';
import '@testing-library/jest-dom';

import { randomObjectFactory } from '@lib/test-utils/factories';

import FactValue from './FactValue';

describe('FactValue component', () => {
it('should render just a scalar value', () => {
const plainString = faker.hacker.noun();

render(<FactValue data={plainString} />);

expect(screen.getByText(plainString)).toBeVisible();
});
const scalarScenarios = [
{
type: 'string',
plain: 'a string',
stringRepresentation: 'a string',
},
{
type: 'number - integer',
plain: 42,
stringRepresentation: '42',
},
{
type: 'number - float',
plain: 42.5,
stringRepresentation: '42.5',
},
{
type: 'boolean',
plain: true,
stringRepresentation: 'true',
},
];

it.each(scalarScenarios)(
'should render just a scalar value of type "$type"',
({ plain, stringRepresentation }) => {
render(<FactValue data={plain} />);

expect(screen.getByText(stringRepresentation)).toBeVisible();
}
);

it('should render just an object tree', () => {
const data = randomObjectFactory.build();
Expand Down

0 comments on commit c7ec2a7

Please sign in to comment.