Skip to content

Commit ad3dd95

Browse files
committed
Remove tests that interact with an element that doesn't exist on the expected page (after re-render)
1 parent 5cc417b commit ad3dd95

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

packages/bygger/src/components/NavFormBuilder.test.jsx

+5-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const DEFAULT_FORM_BUILDER_OPTIONS = {
2424
describe('NavFormBuilder', () => {
2525
beforeAll(() => {
2626
new NavFormioJs.Formio(DEFAULT_PROJECT_URL);
27+
});
28+
29+
beforeEach(() => {
2730
vi.spyOn(NavFormioJs.Formio, 'fetch').mockImplementation(createMockImplementation());
2831
});
2932

@@ -149,6 +152,7 @@ describe('NavFormBuilder', () => {
149152

150153
it('prompts user when removing attachment panel', async () => {
151154
window.confirm = vi.fn().mockImplementation(() => true);
155+
onReadyMock.mockReset();
152156
rerender(
153157
<NavFormBuilder
154158
form={{ ...testform, display: 'skjema' }}
@@ -159,11 +163,6 @@ describe('NavFormBuilder', () => {
159163
);
160164
await waitFor(() => expect(onReadyMock.mock.calls).toHaveLength(1));
161165

162-
// Bruker getByRole, siden findByRole finner element, men feiler på toBeInTheDocument()
163-
const attachmentPanelLink = screen.getByRole('link', { name: 'Vedlegg' });
164-
expect(attachmentPanelLink).toBeInTheDocument();
165-
await userEvent.click(attachmentPanelLink);
166-
167166
const attachmentPanel = await screen.findByRole('button', { name: 'Vedlegg' });
168167
expect(attachmentPanel).toBeInTheDocument();
169168
const builderComponent = findClosestWithAttribute(attachmentPanel, BUILDER_COMP_TESTID_ATTR);
@@ -181,6 +180,7 @@ describe('NavFormBuilder', () => {
181180

182181
it('does not remove attachment panel if user declines prompt', async () => {
183182
window.confirm = vi.fn().mockImplementation(() => false);
183+
onReadyMock.mockReset();
184184
rerender(
185185
<NavFormBuilder
186186
form={{ ...testform, display: 'skjema' }}
@@ -191,11 +191,6 @@ describe('NavFormBuilder', () => {
191191
);
192192
await waitFor(() => expect(onReadyMock.mock.calls).toHaveLength(1));
193193

194-
// Bruker getByRole, siden findByRole finner element, men feiler på toBeInTheDocument()
195-
const attachmentPanelLink = screen.getByRole('link', { name: 'Vedlegg' });
196-
expect(attachmentPanelLink).toBeInTheDocument();
197-
await userEvent.click(attachmentPanelLink);
198-
199194
const attachmentPanel = await screen.findByRole('button', { name: 'Vedlegg' });
200195
expect(attachmentPanel).toBeInTheDocument();
201196
const builderComponent = findClosestWithAttribute(attachmentPanel, BUILDER_COMP_TESTID_ATTR);

0 commit comments

Comments
 (0)