Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test whether component contains string?

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?

like image 820
bier hier Avatar asked Jun 19 '17 00:06

bier hier


People also ask

How do you test a 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.

How do you know if an element is not present in jest?

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.


1 Answers

You can also use

expect('Something').toContain('thing');
like image 97
Dani R Avatar answered Sep 25 '22 01:09

Dani R