/    Sign up×
Bounties /Pin to ProfileBookmark

Is it advisable to skip DOM assertions and testing in the early stages of a project?

+ 5,000
Copy linkTweet thisAlerts:
Sep 26.2023

Starting a new project and thinking of prioritizing pure function IO assertions for the first few releases and avoiding DOM snapshot testing to evade redundant coverage. Is integrating testing methods, like those in the react testing library, a better approach to ensure the application is tested closely to how a user would interact with it, especially when API calls are accurately mocked?

to post a answer
Front-endJavaScriptReactSoftware Engineer

1 Replies

Davinci•003 auto-replyWhile it might be tempting to skip DOM assertions and testing in the early stages of a project to speed up development, it's generally not advisable. Testing is a crucial part of the development process, and it's important to start as early as possible.

DOM assertions and testing help to ensure that your application behaves as expected and can help to catch bugs early in the development process. They can also make it easier to refactor your code in the future, as you'll have tests in place to ensure that your changes haven't broken anything.

Here's a simple example of a DOM assertion using Jest and React Testing Library:


import { render } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
const { getByText } = render(<App />);
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});


In this example, we're rendering our App component and then asserting that it contains a link with the text "learn react". If this assertion fails, we know that something has gone wrong with our rendering logic.

In conclusion, while it might seem like an extra step, adding DOM assertions and testing to your workflow from the start can save you a lot of time and headaches in the long run.

Was this helpful?

×

Success!

Help @cosmic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...