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

Commit 70bd831

Browse files
committed
Added test to (attempt to) demonstrate #249
1 parent b2824ec commit 70bd831

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

.eslintrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
"capIsNewExceptions": ["List", "Map"]
1212
}
1313
],
14-
"react/prefer-stateless-function": 0
14+
"react/prefer-stateless-function": 0,
15+
"no-unused-vars": [
16+
"error",
17+
{
18+
"varsIgnorePattern": "^_"
19+
}
20+
]
1521
}
1622
}

test/field-component-spec.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ describe('<Field /> component', () => {
12811281
});
12821282

12831283
describe('event handlers on control', () => {
1284-
const reducer = modelReducer('test', { foo: '' });
1284+
const reducer = modelReducer('test', { foo: '', bar: '' });
12851285
const store = applyMiddleware(thunk)(createStore)(combineReducers({
12861286
test: reducer,
12871287
}));
@@ -1316,6 +1316,36 @@ describe('<Field /> component', () => {
13161316
'testing');
13171317
});
13181318

1319+
it('should not execute custom onChange functions of unchanged controls', () => {
1320+
const onChangeFn = (val) => val;
1321+
const onChangeFnSpy = sinon.spy(onChangeFn);
1322+
1323+
const field = TestUtils.renderIntoDocument(
1324+
<Provider store={store}>
1325+
<div>
1326+
<Field
1327+
model="test.foo"
1328+
>
1329+
<input type="text" onChange={onChangeFnSpy} />
1330+
</Field>
1331+
<Field
1332+
model="test.bar"
1333+
>
1334+
<input type="text" />
1335+
</Field>
1336+
</div>
1337+
</Provider>
1338+
);
1339+
1340+
const [_, controlBar] = TestUtils.scryRenderedDOMComponentsWithTag(field, 'input');
1341+
1342+
controlBar.value = 'testing';
1343+
1344+
TestUtils.Simulate.change(controlBar);
1345+
1346+
assert.isFalse(onChangeFnSpy.called);
1347+
});
1348+
13191349
it('should persist and return the event even when not returned', () => {
13201350
const onChangeFn = () => {};
13211351
const onChangeFnSpy = sinon.spy(onChangeFn);

0 commit comments

Comments
 (0)