MCPcopy
hub / github.com/final-form/final-form / prepareFieldSubscribers

Function prepareFieldSubscribers

src/FinalForm.fieldSubscribing.test.ts:6–37  ·  view source on GitHub ↗
(
    formSubscription,
    fieldSubscriptions,
    fieldConfig = {},
    config = {},
  )

Source from the content-addressed store, hash-verified

4
5describe("Field.subscribing", () => {
6 const prepareFieldSubscribers = (
7 formSubscription,
8 fieldSubscriptions,
9 fieldConfig = {},
10 config = {},
11 ) => {
12 const form = createForm({ onSubmit: onSubmitMock, ...config });
13 const formSpy = jest.fn();
14 form.subscribe(formSpy, formSubscription);
15 expect(formSpy).toHaveBeenCalled();
16 expect(formSpy).toHaveBeenCalledTimes(1);
17 expect(formSpy.mock.calls[0][0].values).toBeUndefined();
18
19 return {
20 ...Object.keys(fieldSubscriptions).reduce((result, name) => {
21 const spy = jest.fn();
22 form.registerField(
23 name,
24 spy,
25 fieldSubscriptions[name],
26 fieldConfig[name],
27 );
28 expect(spy).toHaveBeenCalled();
29 expect(spy).toHaveBeenCalledTimes(1);
30 const { blur, change, focus } = spy.mock.calls[0][0];
31 result[name] = { blur, change, focus, spy };
32 return result;
33 }, {}),
34 form,
35 formSpy,
36 };
37 };
38
39 it("should provide a list of registered fields", () => {
40 const form = createForm({ onSubmit: onSubmitMock });

Calls 1

createFormFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…