Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Use Array find() for nodes with 'view:' in the id, and check for ok (truthiness) instead of null since
// not found nodes will return undefined instead of null
// VA file number input is not visible; error is shown for empty SSN input
const inputs = ReactTestUtils.scryRenderedDOMComponentsWithTag(form, 'input');
expect(inputs.find(input => input.id === 'root_veteranSocialSecurityNumber')).to.be.ok;
expect(inputs.find(input => input.id === 'root_vaFileNumber')).not.to.be.ok;
const errors = ReactTestUtils.scryRenderedDOMComponentsWithClass(form, 'usa-input-error-message');
expect(errors.find(input => input.id.includes('root_veteranSocialSecurityNumber'))).to.be.ok;
// Check no-SSN box
const noSSNBox = ReactTestUtils.scryRenderedDOMComponentsWithTag(form, 'input')
.find(input => input.id === 'root_view:noSSN');
ReactTestUtils.Simulate.change(noSSNBox,
{
target: {
checked: true
}
});
// No error is shown for empty SSN input; error is shown for empty file number input
const newErrors = ReactTestUtils.scryRenderedDOMComponentsWithClass(form, 'usa-input-error-message');
expect(newErrors.find(input => input.id.includes('root_veteranSocialSecurityNumber'))).not.to.be.ok;
expect(newErrors.find(input => input.id.includes('root_vaFileNumber'))).to.be.ok;
});
it('should submit with no errors with all required fields filled in', () => {
it('Should call onSelect callback ', done => {
const doneOp = () => {
done();
};
const instance = ReactTestUtils.renderIntoDocument(
);
const instanceDom = findDOMNode(instance.menuContainer);
ReactTestUtils.Simulate.click(instanceDom.querySelector(itemClassName));
});
it('Should call onClean callback', done => {
const doneOp = () => {
done();
};
const instance = ReactTestUtils.renderIntoDocument(
);
const instanceDOM = findDOMNode(instance);
ReactTestUtils.Simulate.click(instanceDOM.querySelector('.rs-picker-toggle-clean'));
});
it('test clicks on previous and next buttons', () => {
let elmts = ReactTestUtils.scryRenderedDOMComponentsWithTag(pagination, 'a');
let previous = elmts[0];
let next = elmts[elmts.length - 1];
ReactTestUtils.Simulate.click(next);
expect(ReactDOM.findDOMNode(pagination).querySelector(".selected a").textContent).toBe("2");
ReactTestUtils.Simulate.click(previous);
expect(ReactDOM.findDOMNode(pagination).querySelector(".selected a").textContent).toBe("1");
});
lab.test('it handles a submit event', (done) => {
stub.Actions.sendRequest = function () {
done();
};
const FormEl = React.createElement(Form, {});
const form = ReactTestUtils.renderIntoDocument(FormEl);
const formTag = ReactTestUtils.findRenderedDOMComponentWithTag(form, 'form');
ReactTestUtils.Simulate.submit(formTag);
});
it('Should call onSelect callback', done => {
const doneOp = eventKey => {
if (eventKey === 12) {
done();
}
};
const instance = getDOMNode();
ReactTestUtils.Simulate.click(instance.querySelector('.rs-panel-heading'));
});
customBooleanFlag
/>
<button type="button">
)
}
}
const TestForm = reduxForm({ form: 'testForm' })(Form)
const dom = TestUtils.renderIntoDocument(
)
const button = TestUtils.findRenderedDOMComponentWithTag(dom, 'button')
TestUtils.Simulate.click(button)
expect(renderFields).toHaveBeenCalled()
expect(renderFields).toHaveBeenCalledTimes(2)
const fields = renderFields.mock.calls[1][0]
const expectField = field => {
expect(field).toBeTruthy()
expect(field.input).toBeTruthy()
expect(typeof field.input.onChange).toBe('function')
expect(typeof field.input.onBlur).toBe('function')
expect(typeof field.input.onFocus).toBe('function')
expect(field.meta).toBeTruthy()
expect(field.meta.pristine).toBe(true)
expect(field.meta.dirty).toBe(false)
expect(field.someCustomProp).toBeFalsy()
expect(field.anotherCustomProp).toBeFalsy()
expect(field.customBooleanFlag).toBeFalsy()</button>
function simulateEvent(node, event, mock) {
const eventFn = TestUtils.Simulate[event];
if (!eventFn) {
throw new TypeError(`simulateEvent: event '${event}' does not exist`);
}
eventFn(node, mock);
}