Skip to Content
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
Explore Skills
Cloud Computing
Microsoft Azure
Amazon Web Services (AWS)
Google Cloud
Cloud Migration
Cloud Deployment
Cloud Platforms
Data Engineering
Data Warehouse
SQL
Apache Spark
Microsoft SQL Server
MySQL
Kafka
Data Lake
Streaming & Messaging
NoSQL Databases
Relational Databases
Data Science
Pandas
R
MATLAB
SAS
D3
Power BI
Tableau
Statistics
Exploratory Data Analysis
Data Visualization
AI & ML
Generative AI
Machine Learning
Artificial Intelligence (AI)
Deep Learning
Reinforcement Learning
Natural Language Processing
TensorFlow
Scikit-Learn
Hyperparameter Tuning
MLOps
Programming Languages
Java
JavaScript
Spring
Python
Go
C#
C++
C
Swift
Rust
Functional Programming
Software Architecture
Object-Oriented
Distributed Systems
Domain-Driven Design
Architectural Patterns
IT/Ops
Kubernetes
Docker
GitHub
Terraform
Continuous Delivery
Continuous Integration
Database Administration
Computer Networking
Operating Systems
IT Certifications
Security
Network Security
Application Security
Incident Response
Zero Trust Model
Disaster Recovery
Penetration Testing / Ethical Hacking
Governance
Malware
Security Architecture
Security Engineering
Security Certifications
Design
Web Design
Graphic Design
Interaction Design
Film & Video
User Experience (UX)
Design Process
Design Tools
Business
Agile
Project Management
Product Management
Marketing
Human Resources
Finance
Team Management
Business Strategy
Digital Transformation
Organizational Leadership
Soft Skills
Professional Communication
Emotional Intelligence
Presentation Skills
Innovation
Critical Thinking
Public Speaking
Collaboration
Personal Productivity
Confidence / Motivation
Features
All features
Verifiable skills
AI Academy
Courses
Certifications
Interactive learning
Live events
Superstreams
Answers
Insights reporting
Radar Blog
Buy Courses
Plans
Sign In
Try Now
O'Reilly Platform
book
React快速上手开发
by
Stoyan Stefanov
March 2017
Intermediate to advanced
210 pages
5h 1m
Chinese
Posts & Telecom Press
Content preview from
React快速上手开发
lint
、
Flow
、测试与复验
|
157
这时你的测试就可以成功通过了。
当一个测试的执行不正常时,你可能需要知道实际生成的
HTML
结构是什
么。一个快速简便的方法就是使用
console.log(node.outerHTML)
,让
HTML
内容在控制台中输出。
7.4.5
测试
<Actions>
组件
<Actions>
组件也是一个无状态组件,这意味着你需要把它包裹在另一层
DOM
节点中,以
便随后进行检查。一种方式是像前面对
<Button>
组件所做的那样,将其包裹在
div
中并通
过以下方式访问:
const actions = TestUtils.renderIntoDocument(
<div><Actions /></div>
);
ReactDOM.findDOMNode(actions).children[0]; // <Actions>
组件的根节点
1.
组件包裹层
另一种方式是使用组件包裹层,以方便你随后使用
TestUtils
提供的各种方法寻找需要检
查的节点。
这个包裹层非常简单,可以定义在一个模块中,方便以后重用:
import React from 'react';
class Wrap extends React.Component {
render() {
return <div>{this.props.children}</div>;
}
}
export default Wrap
接下来编写测试模板:
jest
.dontMock('../source/components/Actions') ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial
You might also like
JSON實務手冊
Tom Marrs
C++语言导学(原书第2版)
本贾尼 斯特劳斯特鲁普
React学习手册
Alex Banks, Eve Porcello
数据压缩入门
Colt McAnlis, Aleks Haecky
Publisher Resources
ISBN: 9787115447739