-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Forms): ensure Tools.Log formats arrays with square brackets (#4384)
- Loading branch information
1 parent
461e258
commit 7905694
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/dnb-eufemia/src/extensions/forms/Tools/__tests__/Log.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react' | ||
import { render } from '@testing-library/react' | ||
import { Form, Tools } from '../../' | ||
|
||
describe('Tools.Log', () => { | ||
it('should render data context', () => { | ||
const data = { foo: 'bar' } | ||
render( | ||
<Form.Handler data={data}> | ||
<Tools.Log /> | ||
</Form.Handler> | ||
) | ||
|
||
const element = document.querySelector('output') | ||
expect(element.textContent).toBe(JSON.stringify(data, null, 2) + ' ') | ||
}) | ||
|
||
it('should format array with square brackets', () => { | ||
const data = { foo: ['bar', 'baz'] } | ||
render( | ||
<Form.Handler data={data}> | ||
<Tools.Log /> | ||
</Form.Handler> | ||
) | ||
|
||
const element = document.querySelector('output') | ||
expect(element.textContent).toBe(JSON.stringify(data, null, 2) + ' ') | ||
expect(element.textContent).toContain('[') | ||
expect(element.textContent).toContain('}') | ||
}) | ||
|
||
it('should format "undefined"', () => { | ||
const data = { foo: { bar: undefined } } | ||
render( | ||
<Form.Handler data={data}> | ||
<Tools.Log /> | ||
</Form.Handler> | ||
) | ||
|
||
const element = document.querySelector('output') | ||
expect(element.textContent).toContain('"bar": "undefined"') | ||
}) | ||
}) |