我有一个反应成分:
export class Test extends React.Component<TestProps, TestState> {
...
//the constructor sets the state initially
constructor(props: TestProps) {
this.state = {
thisIsAState: 1;
}
}
//this function updates the state given the num param
updateStat
我想知道反应片段是否与酶的快照兼容。现在看来,来自React 16+的片段在酶的shallow()方法中被呈现为符号,这会导致转换错误:"TypeError: Cannot convert a Symbol value to a string"。
这是我的测试:
it('should render successfully', () => {
const wrapper = shallow(
<Sections
data={mappedMockData}
sections={mappedMockData.secti
我正在创建一个天气应用程序,它与反应和测试它的酶,在每个页面重新加载和最初的页面加载背景图像应该改变/加载
App.js
function App() {
const [background, setBackground] = useState('');
async function fetchBgImage() {
// getRandomImage returns a link fetched from the api
setBackground(await getRandomImage());
}
useEffect(() =>
我想测试,看看一个图像是否正确地加载到一个反应应用程序。我已经决定检查嵌套在React组件中的img元素的img属性。我想使用Jest测试框架,如果需要的话,使用酶测试工具。
通过深入研究浅反应测试组件的Object.keys,我能够想出以下解决方案。我不确定的行是用星号表示的。
import React from 'react';
import {shallow} from 'enzyme';
import App from './App';
it('should have the logo image',
问题
我刚开始做酶和反应测试。我试图让酶与业力和webpack一起工作在一个琐碎的反应部件上。我的问题是包装器上的prop()返回null,我不知道为什么。
Greeter.js
import React from 'react';
/*
* A trivial component we added while trying to get the react testing working
* */
export default class Greeter extends React.Component {
constructor(props) {
super