Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit ac382a6

Browse files
committed
Merge pull request #251 from elodszopos/master
Extend custom onChange function test cases
2 parents 70bd831 + 97076c0 commit ac382a6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/field-component-spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,39 @@ describe('<Field /> component', () => {
13461346
assert.isFalse(onChangeFnSpy.called);
13471347
});
13481348

1349+
it('should only execute custom onChange function pertaining to the changed input', () => {
1350+
const onChangeFnFoo = (val) => val;
1351+
const onChangeFnBar = (val) => val;
1352+
const onChangeFnFooSpy = sinon.spy(onChangeFnFoo);
1353+
const onChangeFnBarSpy = sinon.spy(onChangeFnBar);
1354+
1355+
const field = TestUtils.renderIntoDocument(
1356+
<Provider store={store}>
1357+
<div>
1358+
<Field
1359+
model="test.foo"
1360+
>
1361+
<input type="text" onChange={onChangeFnFooSpy} />
1362+
</Field>
1363+
<Field
1364+
model="test.bar"
1365+
>
1366+
<input type="text" onChange={onChangeFnBarSpy} />
1367+
</Field>
1368+
</div>
1369+
</Provider>
1370+
);
1371+
1372+
const [_, controlBar] = TestUtils.scryRenderedDOMComponentsWithTag(field, 'input');
1373+
1374+
controlBar.value = 'testing';
1375+
1376+
TestUtils.Simulate.change(controlBar);
1377+
1378+
assert.isFalse(onChangeFnFooSpy.called);
1379+
assert.isTrue(onChangeFnBarSpy.called);
1380+
});
1381+
13491382
it('should persist and return the event even when not returned', () => {
13501383
const onChangeFn = () => {};
13511384
const onChangeFnSpy = sinon.spy(onChangeFn);

0 commit comments

Comments
 (0)