Это вопрос мнения, но шаблон, который мне нравится, это
- определить ожидаемый массив
- выбрать все дочерние элементы по атрибутам, которые не проверяются
- сравнить фактический массив с ожидаемым
const expected = [
{
text: '',
classes: 'diffed-chunk diffed-chunk--pending',
},
{
text: '1',
classes: 'diffed-chunk',
},
{
text: '2',
classes: 'diffed-chunk',
},
];
const getText = el => el.textContent.trim()
it('should have expected text', () => {
cy.get('.diffed-chunks div').then(els => {
const texts = [...els].map(getText)
expect(texts).to.deep.eq(expected.map(x => x.text))
})
});
const getClasses = el => el.className
it('should have classes', () => {
cy.get('.diffed-chunks div').then(els => {
const classes = [...els].map(getClasses)
expect(classes).to.deep.eq(expected.map(x => x.classes))
})
});