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

Commit b5be94f

Browse files
committed
get a failing test for my scenario
1 parent 95b1054 commit b5be94f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/field-parser-spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,35 @@ describe('<Field parser={...} />', () => {
8686

8787
assert.equal(store.getState().test.foo, 'INITIAL');
8888
});
89+
90+
it('should update the viewValue with only the data returned by parser', () => {
91+
const initial = { foo: '0123456789' };
92+
const expected = '0123';
93+
94+
const store = createStore(combineReducers({
95+
test: modelReducer('test', initial),
96+
testForm: formReducer('test', initial),
97+
}));
98+
99+
const parseValue = val => val.substring(0, 4);
100+
101+
const field = TestUtils.renderIntoDocument(
102+
<Provider store={store}>
103+
<Field
104+
model="test.foo"
105+
parser={parseValue}
106+
>
107+
<input type="text" />
108+
</Field>
109+
</Provider>
110+
);
111+
112+
const input = TestUtils.findRenderedDOMComponentWithTag(field, 'input');
113+
input.value = '012345678912341268374612837';
114+
TestUtils.Simulate.change(input);
115+
116+
assert.equal(input.value, expected);
117+
118+
assert.equal(store.getState().test.foo, expected);
119+
});
89120
});

0 commit comments

Comments
 (0)