Skip to content

Commit

Permalink
Update StandardFieldComponent to RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
wwahammy committed Dec 14, 2024
1 parent c28ec7b commit 9ebb553
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
// License: LGPL-3.0-or-later
import * as React from 'react';
import {shallow} from 'enzyme'
import {render, screen} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import StandardFieldComponent from './StandardFieldComponent'
import toJson from 'enzyme-to-json';

describe('StandardFieldComponent', () => {
test('works with no children', () => {
var field = shallow(<StandardFieldComponent inError={false} />)
var field = render(<StandardFieldComponent inError={false} />)


expect(toJson(field)).toMatchSnapshot()
expect(field.baseElement).toMatchSnapshot()
})
test('works with a child', () => {
var field = shallow(<StandardFieldComponent inError={false}><input/></StandardFieldComponent>);
var field = render(<StandardFieldComponent inError={false}><input/></StandardFieldComponent>);

expect(toJson(field)).toMatchSnapshot()
expect(field.baseElement).toMatchSnapshot()
})

test('sets error message properly', () => {
var field = shallow(<StandardFieldComponent inError={true} error={"Something more"}><input/></StandardFieldComponent>);
var field = render(<StandardFieldComponent inError={true} error={"Something more"}><input/></StandardFieldComponent>);

expect(toJson(field)).toMatchSnapshot()
expect(field.baseElement).toMatchSnapshot()
})
})
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`StandardFieldComponent sets error message properly 1`] = `
<div>
<input />
<div
className="help-block"
role="alert"
>
Something more
<body>
<div>
<div>
<input />
<div
class="help-block"
role="alert"
>
Something more
</div>
</div>
</div>
</div>
</body>
`;

exports[`StandardFieldComponent works with a child 1`] = `
<div>
<input />
</div>
<body>
<div>
<div>
<input />
</div>
</div>
</body>
`;

exports[`StandardFieldComponent works with no children 1`] = `<div />`;
exports[`StandardFieldComponent works with no children 1`] = `
<body>
<div>
<div>
</div>
</div>
</body>
`;

0 comments on commit 9ebb553

Please sign in to comment.