我正在使用酶来编写测试,在这种情况下,将上下文添加到组件let months = ["Jan" , "Feb", "Mar" , "April"]
let unitsSold = [1000.0 , 200.0, 200.0 , 200.0]
func setChart(dataPoints: [String], values: [Double]) {
var dataEntries: [ChartDataEntry] = []
for i in 0..<dataPoints.count {
let dataEntry = ChartDataEntry(x: values[i], y: Double(i))
dataEntries.append(dataEntry)
}
print(dataEntries)
let pieChartDataSet = PieChartDataSet(values: dataEntries, label: "Loans")
let pieChartData = PieChartData(dataSet: pieChartDataSet)
pieChart.data = pieChartData
pieChart.holeRadiusPercent = 0.0
pieChart.transparentCircleRadiusPercent = 0.0
pieChart.holeColor = UIColor.clear
var colors: [UIColor] = []
for j in 0..<dataPoints.count {
let red = Double(arc4random_uniform(256))
let green = Double(arc4random_uniform(256))
let blue = Double(arc4random_uniform(256))
let color = UIColor(red: CGFloat(red/255), green: CGFloat(green/255), blue: CGFloat(blue/255), alpha: 1)
colors.append(color)
}
pieChartDataSet.selectionShift = 0.0
pieChartDataSet.drawValuesEnabled = false
pieChartDataSet.sliceSpace = 8.0
pieChartDataSet.colors = colors
pieChart.legend.enabled = false
}
之前,呈现的快照未显示任何元素,并且每次添加consumer component
时或dive()
我遇到相同的错误
使用上下文时如何访问元素
shallow()
答案 0 :(得分:1)
Enzyme
在v3.10.0
lacked support of React's new Context API之前。
浅:支持渲染和潜水()createContext()提供者和使用者(#1966)
请确保您使用的是enzyme
v3.10.0
或更高版本和 enzyme-adapter-react-16
v1.15.1
或更高版本。