Reactjs 如何测试动态页面标题?
我正在使用并根据某些条件更改文档页面标题 我如何用计算机测试这种行为 我试过类似的东西Reactjs 如何测试动态页面标题?,reactjs,jestjs,jsdom,react-testing-library,react-helmet,Reactjs,Jestjs,Jsdom,React Testing Library,React Helmet,我正在使用并根据某些条件更改文档页面标题 我如何用计算机测试这种行为 我试过类似的东西 const { debug } = render(<TitleChangingComponent title="Test" />, { container: document.head, }); debug(); const{debug}=render({ 容器:document.head, }); 调试(); 但它只是在调试输出中显示一个空。此外,我不能100%确定这是否与一般的re
const { debug } = render(<TitleChangingComponent title="Test" />, {
container: document.head,
});
debug();
const{debug}=render({
容器:document.head,
});
调试();
但它只是在调试输出中显示一个空。此外,我不能100%确定这是否与一般的react测试库或jsdom相关(我使用Jest进行测试)。我不会为此使用
react测试库
我会在E2E测试中对此进行测试,例如使用
cy.title().should('eq','')
固执己见的:
它是使用单元测试和副作用以及使用端到端测试的用户交互来测试组件和纯逻辑。这实际上并没有回答这个问题。我认为它更多地与以及它写入DOM的方式有关。
cy.title().should('eq', '<your-title>')