I am trying to get my head around jest. This is my test:
test('whether contains className', () => {
let list = [
{
id: 12,
name: 'two',
completed: true
}
];
const wrapper = shallow(
<Todos todos={list}>
</Todos>
);
expect(wrap).toMatch(/strikethrough/);
});
How can I check whether a component contains a (sub)string inside the component?
Component testing is performed by testers. 'Unit Testing' is performed by the developers where they do the testing of the individual functionality or procedure. After Unit Testing is performed, the next testing is component testing. Component testing is done by the testers.
Query the element. The most important thing to note when testing for non-existence is that you'll have to query items. When looking for an element, you might have used getBy or getAllBy and then something. This works fine if we know the element exists, but Jest will throw an error when these are not found.
You can also use
expect('Something').toContain('thing');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With