Home > Blockchain >  Unit testing component text -- philosophy
Unit testing component text -- philosophy

Time:04-08

I'm a bit new to unit testing, and I've really only tested methods and things. I'm curious about components like <h1>text</h1> Is it common to unit test the value inside h1? I understand that it would be useful to see in the tests that it has changed, and that the test knows, similar to knowing if any other method or item has changed. But it seems like a lot of work to unit test every line of text in a project. Thoughts? Is it common to unit test text? I understand how framework pieces like Vuetify or React-bootstrap it would be vital to making sure it is rendered in the correct spots, but is it useful in standard projects

CodePudding user response:

The main content of the test is code logic and branching, such as the logic encapsulated by if...else..., functions.

For unstructured and static content like HTML, snapshot testing can be done. You don't need to find every static content and assert its values. Snapshot testing ensures that these static content cannot be accidentally modified.

If there is code logic that changes the content of the h1 tag, you need to test the code logic and assert what was before the change and what happened after the change.

  • Related