一、
1 var jest = require(‘jest‘); 2 3 jest.dontMock(‘../CheckboxWithLabel.js‘); 4 describe(‘CheckboxWithLabel‘, function() { 5 it(‘changes the text after click‘, function() { 6 var React = require(‘react/addons‘); 7 var CheckboxWithLabel = require(‘../CheckboxWithLabel.js‘); 8 var TestUtils = React.addons.TestUtils; 9 var checkbox = TestUtils.renderIntoDocument( < CheckboxWithLabel labelOn = "On" 10 labelOff = "Off" / > ); 11 var label = TestUtils.findRenderedDOMComponentWithTag(checkbox, ‘label‘); 12 expect(label.getDOMNode().textContent).toEqual(‘Off‘); 13 var input = TestUtils.findRenderedDOMComponentWithTag(checkbox, ‘input‘); 14 TestUtils.Simulate.change(input); 15 expect(label.getDOMNode().textContent).toEqual(‘On‘); 16 }); 17 });
时间: 2024-10-22 14:05:07