Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function addTodo($component, todo) {
const node = $component.find('.new-todo')[0];
// TODO: this exposes too much of the internals; figure out a way to write
// tests without knowing all of this
Simulate.change(node, { target: { value: todo } });
Simulate.keyDown(node, {
keyCode: ENTER
});
}
it('should allow user input as tags', (done) => {
if (navigator.userAgent.indexOf(' Chrome') === -1) {
done();
return;
}
const node = instance.getInputDOMNode();
node.focus();
node.value = 'A';
Simulate.change(node);
setTimeout(() => {
Simulate.keyDown(node, {
keyCode: KeyCode.ENTER,
});
setTimeout(() => {
expect(instance.state.value.map(v => v.key)).toContain('A');
done();
}, 100);
}, 100);
});
});
it('updates `value` when the input`s value changes', () => {
const input = findRenderedDOMComponentWithTag(inputWrapper, 'input')
Simulate.change(input, { target : { value : '102' } })
expect(inputWrapper.refs.input.value).toEqual('1.02')
})
instance.context.router = { push };
const requestBtnComponent = findRenderedComponentWithType(instance, RequestBtn);
const requestBtn = findRenderedDOMComponentWithClass(requestBtnComponent, 'btn__request');
Simulate.click(requestBtn);
const requestPopup = findRenderedComponentWithType(instance, RequestPopup);
const expirationInput = findRenderedDOMComponentWithClass(requestPopup, 'expiration');
expirationInput.value = '5';
Simulate.change(expirationInput);
const btnOk = findRenderedDOMComponentWithClass(requestPopup, 'btn__ok');
Simulate.click(btnOk);
props.updateError.should.be.calledWith('Password Required');
const passwordInput = findRenderedDOMComponentWithClass(requestPopup, 'password');
passwordInput.value = 'secret';
Simulate.change(passwordInput);
Simulate.click(btnOk);
props.postTransaction.should.be.calledWith({
db_author: 'Sandy',
cr_author: 'Mindy',
cr_latlng: '0,0',
expiration_time: 5,
transaction_item: [{
key: 0,
name: 'item1',
quantity: 1,
value: 25,
db_account: 'Sandy',
cr_account: 'Mindy'
}],
username: 'JonSnow',
props.postTransaction = stub();
props.postTransaction.returns({
then: (f) => (f({}))
});
const push = spy();
instance = renderIntoDocument();
instance.context.router = { push };
const requestBtnComponent = findRenderedComponentWithType(instance, RequestBtn);
const requestBtn = findRenderedDOMComponentWithClass(requestBtnComponent, 'btn__request');
Simulate.click(requestBtn);
const requestPopup = findRenderedComponentWithType(instance, RequestPopup);
const expirationInput = findRenderedDOMComponentWithClass(requestPopup, 'expiration');
expirationInput.value = '5';
Simulate.change(expirationInput);
const btnOk = findRenderedDOMComponentWithClass(requestPopup, 'btn__ok');
Simulate.click(btnOk);
props.updateError.should.be.calledWith('Password Required');
const passwordInput = findRenderedDOMComponentWithClass(requestPopup, 'password');
passwordInput.value = 'secret';
Simulate.change(passwordInput);
Simulate.click(btnOk);
props.postTransaction.should.be.calledWith({
db_author: 'Sandy',
cr_author: 'Mindy',
cr_latlng: '0,0',
expiration_time: 5,
transaction_item: [{
key: 0,
export function fillInput(lock, name, value) {
Simulate.change(qInput(lock, name, true), {target: {value: value}});
}
instance = renderIntoDocument(
);
const push = spy();
instance.context.router = { push };
const errorMessage = findRenderedDOMComponentWithClass(instance, 'error-message');
const btnOk = findRenderedDOMComponentWithClass(instance, 'btn__ok');
const passwordInput = findRenderedDOMComponentWithTag(instance, 'input');
Simulate.click(btnOk);
errorMessage.textContent.should.equal('Password required');
passwordInput.value = 'abcd1234';
Simulate.change(passwordInput);
Simulate.click(btnOk);
push.should.be.calledWith('/AccountProfile/Success');
});
const onChange = jest.fn((checked) => {
props = Object.assign({}, props, { checked });
});
let control = renderIntoDocument();
let input = findRenderedDOMComponentWithTag(control, 'input');
Simulate.change(input, { target: { checked: true } });
control = renderIntoDocument();
input = findRenderedDOMComponentWithTag(control, 'input');
expect(input.checked).toBe(true);
expect(onChange.mock.calls.length).toBe(1);
Simulate.change(input, { target: { checked: false } });
control = renderIntoDocument();
input = findRenderedDOMComponentWithTag(control, 'input');
expect(input.checked).toBe(false);
expect(onChange.mock.calls.length).toBe(2);
});
});
<option label="二" value="2">2</option>
<option label="十一" value="11">11</option>
, div);
ReactDOM.findDOMNode(select.refs.selection).focus();
Simulate.click(ReactDOM.findDOMNode(select.refs.selection));
select.getInputDOMNode().value = 1;
Simulate.change(select.getInputDOMNode());
expect($(select.getPopupDOMNode()).find('.rc-select-dropdown-menu-item').length).toBe(0);
select.getInputDOMNode().value = 2;
Simulate.change(select.getInputDOMNode());
expect($(select.getPopupDOMNode()).find('.rc-select-dropdown-menu-item').length).toBe(0);
select.getInputDOMNode().value = '一';
Simulate.change(select.getInputDOMNode());
expect($(select.getPopupDOMNode()).find('.rc-select-dropdown-menu-item').length).toBe(2);
select.getInputDOMNode().value = '二';
Simulate.change(select.getInputDOMNode());
expect($(select.getPopupDOMNode()).find('.rc-select-dropdown-menu-item').length).toBe(1);
});
});
it(`filters its items`, () => {
Simulate.change(node, {target: {value: 'o'}});
expect(getItems()).length.to.be(2);
});
});