我正在使用Jest作为测试工具。我无法测试以下情况:
<div class={`${this.isPaginationRequired ? 'search-pagination pull-right' : 'pagination-hide'}`} id = "pagination">
我正在为以下情况编写测试用例:
it('pagination should be visible if isPaginationRequired is set to true', () => {
const paginationDiv = element.querySelector('#pagination');
expect(paginationDiv.classList).toContain('search-pagination');
expect(paginationDiv.classList).toContain('pull-right');
});
it('pagination should not be visible if isPaginationRequired is set to false', async () => {
const paginationDiv = element.querySelector('#pagination');
// testWindow.flush();
searchComponent.isPaginationRequired = false;
expect(paginationDiv.className).toBe('pagination-hide');
})
但是问题出在将isPaginationRequired设置为false paginationDiv.className是 search-pagination pull-right
之后的第二个测试用例中