在这里格式化...在堆栈中尝试但是没有那么好...... https://gist.github.com/js08/22654f6cd2f160aa2e0a
数组中的单个对象:
shallowRenderer.render(<SportsList disclosures ={[ 'id': 'foo', 'text': 'car racing' ]} />);
数组中的多个对象:
shallowRenderer.render(<SportsList disclosures ={[ {id: 100, text: 'car racing'}, {id: 10, text: 'hello vworld'}, {id: 100, text: 'car racing'} ]} />);
import {expect} from 'chai';
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import SportsList from '../../src/components/footer/disclosure-list.jsx';
import initializeJsDom from '../test-utils/dom.js';
import {getGridLayoutClasses} from 'sports-css-grids';
describe('shallow renderer tests for disclosure-list ', function() {
let shallowRenderer = TestUtils.createRenderer();
it('should render correctly', () => {
shallowRenderer.render(<SportsList disclosures ={[ {id: 100, text: 'car racing'}, {id: 10, text: 'hello vworld'}, {id: 100, text: 'car racing'} ]} />);
//shallowRenderer.render(<SportsList disclosures ={[ 'id': 'foo', 'text': 'car racing' ]} />);
let sportsOutputElement = shallowRenderer.getRenderOutput();
let sportsTitle = sportsOutputElement.props.children[0].key;
let text = sportsOutputElement.props.children[0].props.dangerouslySetInnerHTML.__html;
//result succeful for single value
expect(sportsTitle).equal('100');
//result succeful for single value
expect(text).equal('car racing');
});
});
json structure
renderedElement - multiple arrays-- -- >
{
"type": "div",
"key": null,
"ref": null,
"props": {
"className": "pageFooter-disclosures",
"children": [{
"type": "p",
"key": "100",
"ref": null,
"props": {
"dangerouslySetInnerHTML": {
"__html": "hello world"
}
},
"_owner": null,
"_store": {}
}, {
"type": "p",
"key": "10",
"ref": null,
"props": {
"dangerouslySetInnerHTML": {
"__html": "hello vworld"
}
},
"_owner": null,
"_store": {}
}, {
"type": "p",
"key": "100",
"ref": null,
"props": {
"dangerouslySetInnerHTML": {
"__html": "hello world"
}
},
"_owner": null,
"_store": {}
}]
},
"_owner": null,
"_store": {}
}√
should render correctly(3 ms)
答案 0 :(得分:0)
使用来自expect
的{{1}},您可以使用eql来测试对象的深度相等性
chai