2016-07-29 112 views
0

當前我正在使用Jest來測試我的React應用程序。我有以下代碼:反應不渲染檢查屬性

var component = TestUtils.renderIntoDocument(<input type="radio" defaultChecked={true}/>) 
var node = ReactDOM.findDOMNode(component) 

console.log(node.outerHTML) 
// Return 
// <input data-reactroot="" type="radio"> 

爲什麼選中的屬性不是呈現?

+0

http://www.webpackbin.com/E1jvGHB_W –

回答

0

我更新了我的反應後,它的工作原理。但是在測試中,outerHTML並不像Vijay所說的那樣顯示檢查的屬性。所以,使用以下期望:

expect(node.checked).toEqual(true); 
1

checked屬性可能不存在於outerHTML中。但是對node.checked的測試返回true。

import React from 'react'; 
import TestUtils from 'react-addons-test-utils'; 
import ReactDOM from 'react-dom'; 

describe('radio_test',() => { 
    it('outputs default',() => { 
    const component = TestUtils.renderIntoDocument(<input type="radio" defaultChecked={true}/>); 
    const node = ReactDOM.findDOMNode(component); 
    expect(node.type).toEqual('radio'); 
    expect(node.checked).toEqual(true); 
    }); 
}); 
+0

感謝您的幫助。 –