Skip to content

Regs3k asynchronous tests aren't testing anything #7374

@anselmbradford

Description

@anselmbradford

These two tests don't actually test anything and should be refactored to handle the async call to fetch

it('should load recent notices', () => {
// Fire `load` event
simulateEvent('load', window, { currentTarget: window });
// Wait for window.load to trigger.
setTimeout(() => {
const numNotices = document.querySelectorAll('.m-list_link').length;
expect(numNotices).toEqual(4);
}, 1000);
});
it('should fail to load recent notices', (done) => {
fetch.mockReject(new Error('Server error!'));
// Fire `load` event
simulateEvent('load', window, { currentTarget: window });
setTimeout(() => {
// eslint-disable-next-line no-console
expect(console.error).toBeCalled();
done();
}, 100);
});

The call to fetch happens inside a window.onload event.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions