假设我有组件,当调用render()时,组件被呈现,然后挂载到DOM节点上:
render() {
// Render the HTML elements
const content = renderParent();
// Mount onto the DOM element with id `app`;
let element = document.getElementById('app');
element.innerHTML = '';
element.appendChild(div);
}
renderParent(
我是使用UseHistory钩子在反应路由器v5.1.2与类型记录?在运行单元测试时,我遇到了问题。
TypeError:无法读取未定义的属性“历史记录”。
import { mount } from 'enzyme';
import React from 'react';
import {Action} from 'history';
import * as router from 'react-router';
import { QuestionContainer } from './QuestionsContai
我们有一个,在Jest测试中遇到了麻烦:
import React from 'react';
import { render } from '@testing-library/react-native';
import MyScreen from '../../../../../src/screens/MyScreen/index';
import Provider from '../../../../__helpers__/Provider';
import { t } from 'core/utils';
i
我正在尝试使用jest-dom来测试组件的样式,但我遇到了错误:
"TypeError: expect(...).toHaveStyle is not a function"
我的组件是一个带有样式组件的简单链接:
import styled from 'styled-components'
export const Link = styled.a`
color: #fff;
`
在我的测试中,我做的是:
describe('Link', () => {
it('should display color on the li
我在使用的jest匹配器的StencilJS中进行了一个单元测试。当我运行测试时,它抛出了一个错误:
TypeError: Right-hand side of 'instanceof' is not an object
at checkHtmlElement (node_modules/@testing-library/jest-dom/dist/utils.js:61:69)
at Object.toHaveFormValues (node_modules/@testing-library/jest-dom/dist/to-have-form-val
使用Jest模拟第三方库中的方法的问题。所以我有一个像这样实现的组件 import {foo} from 'bar'
function Component() {
// use foo somewhere in the component
} 在测试中我试着模仿foo,所以 import {foo} from 'bar'
jest.mock('bar')
test('test', () => {
foo.mockReturnValue(...)
}) 这工作得很好,但是一旦我将jest.mock('bar
useEffect通常使用更新状态的承诺。
此更新会在jest中引起长时间警告:Warning: An update to null inside a test was not wrapped in act(...).
如何正确地为这种情况编写Jest测试?
实例,可复制的示例:
index.test.js
import React from "react";
import Hello from "./Hello";
import { create, act } from "react-test-renderer";
it("work
html = '<h1>foo</h1><p>bar</p>';
virtual_dom = $(html);
console.log(virtual_dom);
// logs a data structure recognizable as a DOM with the h1 and p from the string
jQuery是否提供了一种从virtual_dom中删除段落的方法,以便console.log(virtual_dom)只记录带有h1标记的DOM,就像$('p').remove()一样,但会影