Skip to content

Commit

Permalink
test: Fixed tests
Browse files Browse the repository at this point in the history
Asyncronous await waitfor needed for certain expect calls. Seems to _only_ cause issues on released erm-testing, not on snapshot version or locally -.-
  • Loading branch information
EthanFreestone committed Oct 31, 2024
1 parent 77b21f0 commit a181222
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
10 changes: 6 additions & 4 deletions lib/DocumentFilter/DocumentFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ describe('DocumentFilter', () => {
expectedParsedFilterData
) => {
describe(activeFilterTitle, () => {
beforeEach(() => {
beforeEach(async () => {
await mockPFD.mockClear();
renderComponent = renderWithIntl(
<MemoryRouter>
<DocumentFilter
Expand Down Expand Up @@ -125,14 +126,15 @@ describe('DocumentFilter', () => {

describe('testing parsedFilterData', () => {
beforeEach(async () => {
mockPFD.mockClear();
await waitFor(async () => {
await Button('Test parsed filter data').click();
});
});

test('parsed filter data is as expected', () => {
expect(mockPFD.mock.calls[0][0]).toEqual(expectedParsedFilterData);
test('parsed filter data is as expected', async () => {
await waitFor(async () => {
await expect(mockPFD.mock.calls[0][0]).toEqual(expectedParsedFilterData);
});
});
});
});
Expand Down
31 changes: 20 additions & 11 deletions lib/DocumentFilter/DocumentFilterForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ describe('DocumentFilterForm', () => {
await Button('Edit document filters').exists();
});

test('filter form is not open', () => {
test('filter form is not open', async () => {
const { queryByText } = renderComponent;
expect(queryByText('DocumentFilterFieldArray')).not.toBeInTheDocument();
await waitFor(async () => {
await expect(queryByText('DocumentFilterFieldArray')).not.toBeInTheDocument();
})

Check failure on line 92 in lib/DocumentFilter/DocumentFilterForm.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Missing semicolon
});

describe('opening the filter form', () => {
Expand All @@ -97,9 +99,11 @@ describe('DocumentFilterForm', () => {
});
});

test('filter form is open', () => {
test('filter form is open', async () => {
const { queryByText } = renderComponent;
expect(queryByText('DocumentFilterFieldArray')).toBeInTheDocument();
await waitFor(async () => {
await expect(queryByText('DocumentFilterFieldArray')).toBeInTheDocument();
});
});
});
});
Expand Down Expand Up @@ -144,9 +148,11 @@ describe('DocumentFilterForm', () => {
});
});

test('filter form is open', () => {
test('filter form is open', async () => {
const { queryByText } = renderComponent;
expect(queryByText('DocumentFilterFieldArray')).toBeInTheDocument();
await waitFor(async () => {
await expect(queryByText('DocumentFilterFieldArray')).toBeInTheDocument();
});
});

describe('making form dirty for submittal', () => {
Expand All @@ -167,19 +173,22 @@ describe('DocumentFilterForm', () => {
beforeEach(async () => {
// Submit form
await waitFor(async () => {
// screen.debug();
// There is no translation for this across stripes-erm-components rn, so no use for intlKey.
await Button('ui-test-implementor.saveAndClose').click();
});
});

test(`submit handler acted as expected for ${filtersInfo}`, () => {
expect(filterHandlers.state.mock.calls[0][0]).toEqual(expectedSubmit);
test(`submit handler acted as expected for ${filtersInfo}`, async () => {
await waitFor(async () => {
await expect(filterHandlers.state.mock.calls[0][0]).toEqual(expectedSubmit);
});
});

test('filter form is not open', () => {
test('filter form is not open', async () => {
const { queryByText } = renderComponent;
expect(queryByText('DocumentFilterFieldArray')).not.toBeInTheDocument();
await waitFor(async () => {
await expect(queryByText('DocumentFilterFieldArray')).not.toBeInTheDocument();
});
});
});
});
Expand Down

0 comments on commit a181222

Please sign in to comment.