PhantomJS中的Angular 2模板解析错误?

时间:2016-10-11 09:21:12

标签: angular phantomjs

在角度2中对组件进行单元测试时遇到问题:

enter image description here

此错误仅在运行测试时显示,在Chrome上运行良好。

任何帮助,谢谢。

1 个答案:

答案 0 :(得分:2)

  

此错误仅在运行测试时显示

就像将public class CombinedChartActivity extends BaseActivity { private CombinedChart combinedChart; private BarChart barChart; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_combined_chart); combinedChart = (CombinedChart) findViewById(R.id.chart); barChart = (BarChart) findViewById(R.id.barChart); initChart(combinedChart); initChart(barChart); barChart.setData(getBarData()); CombinedData combinedData = new CombinedData(); combinedData.setXVals(getXVals()); combinedData.setData(getLineData()); combinedData.setData(getBarData()); combinedChart.setData(combinedData); } private void initChart(BarLineChartBase barLineChartBase) { barLineChartBase.setDescription(""); barLineChartBase.getAxisLeft().setEnabled(false); barLineChartBase.getAxisRight().setEnabled(false); barLineChartBase.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM); barLineChartBase.getXAxis().setGridColor(R.color.white); barLineChartBase.getXAxis().setAvoidFirstLastClipping(true); barLineChartBase.setBackgroundColor(Color.WHITE); } private BarData getBarData() { List<IBarDataSet> iBarDataSets = new ArrayList<>(); ArrayList<BarEntry> barEntries = new ArrayList<>(); for (int i = 0; i < 7; i++) { BarEntry barEntry = new BarEntry(i + 1, i); barEntries.add(barEntry); } BarDataSet barDataSet = new BarDataSet(barEntries, "Bar1"); barDataSet.setColor(Color.rgb(60, 220, 78)); barDataSet.setAxisDependency(YAxis.AxisDependency.LEFT); ArrayList<BarEntry> barEntries2 = new ArrayList<>(); for (int i = 0; i < 7; i++) { BarEntry barEntry = new BarEntry((float) (i + Math.random() * 10), i); barEntries2.add(barEntry); } BarDataSet barDataSet1 = new BarDataSet(barEntries2, "Bar2"); barDataSet1.setColor(R.color.level_3); barDataSet1.setAxisDependency(YAxis.AxisDependency.RIGHT); iBarDataSets.add(barDataSet); iBarDataSets.add(barDataSet1); BarData barData = new BarData(getXVals(), iBarDataSets);[![enter image description here][1]][1] return barData; } private LineData getLineData() { ArrayList<Entry> entries = new ArrayList<>(); for (int i = 0; i < 7; i++) { Entry entry = new Entry((float) (Math.random() * 10), i); entries.add(entry); } List<ILineDataSet> iLineDataSets = new ArrayList<>(); LineDataSet lds1 = new LineDataSet(entries, "Line"); lds1.setLineWidth(0.2f); lds1.setColor(R.color.level_3); lds1.setDrawFilled(true); lds1.setFillAlpha(150); lds1.setFillColor(R.color.level_2); lds1.setDrawValues(false); lds1.setHighlightEnabled(true); lds1.setDrawHorizontalHighlightIndicator(false); lds1.setHighLightColor(R.color.white); lds1.setDrawCubic(true); lds1.setDrawCircles(true); lds1.setCircleColor(R.color.white); lds1.setCircleColorHole(R.color.theme_orange); lds1.setAxisDependency(YAxis.AxisDependency.LEFT); iLineDataSets.add(lds1); LineData lineData = new LineData(getXVals(), iLineDataSets); return lineData; } private List<String> getXVals() { ArrayList<String> xVals = new ArrayList<>(); xVals.add("Monday"); xVals.add("Tuesday"); xVals.add("Wednesday"); xVals.add("Thursday"); xVals.add("Friday"); xVals.add("Saturday"); xVals.add("Sunday"); return xVals; } } 导入应用程序模块一样,您还需要进行测试。 ReactiveFormModule的用途是为测试环境配置一个模块(就像TestBed.configureTestingModule从头开始。因此,如果您在要测试的组件中使用表单,则需要添加表单模块,就像在应用程序中一样

@NgModule