如何检查 React Jest 测试用例中的文本内容顺序?

How to check text content order in react Jest test cases?

我正在使用 jest 和 react 测试库来编写测试用例。我已经通过 id 调用了元素,现在我需要检查文本内容是否具有特定顺序。

const getId = queryByAttribute.bind(null,'id');
const result = getById(component.container,'student-details-page');

现在result.textContent是Details:TeacherJin;SugaStudentDaphne 我需要检查老师总是先来,然后是学生。它实际上是 values.i.e 在 UI 它是

Details.  Teacher
          Jin
          Suga
        
          Student
          Daphne

我该如何检查?

您可以创建一个正则表达式模式来检查单词 Teacher 是否出现在 Student 之前。

expect(result.textContent.match(/.*Teacher.*Student.*/)).not.toBeNull()