-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathwarnings.test.tsx
More file actions
47 lines (40 loc) · 1.39 KB
/
warnings.test.tsx
File metadata and controls
47 lines (40 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React from 'react';
import { render } from '@testing-library/react';
import { warnOnce } from '@cloudscape-design/component-toolkit/internal';
import AttributeEditor from '../../../lib/components/attribute-editor';
jest.mock('@cloudscape-design/component-toolkit/internal', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit/internal'),
warnOnce: jest.fn(),
}));
afterEach(() => {
(warnOnce as jest.Mock).mockReset();
});
describe('AttributeEditor component', () => {
test('warns when a definition has no label', () => {
render(
<AttributeEditor
addButtonText="Add"
removeButtonText="Remove"
definition={[{ label: 'Key label', control: () => 'key' }]}
items={[{}]}
gridLayout={[{ rows: [[1]] }]}
/>
);
expect(warnOnce).not.toHaveBeenCalled();
render(
<AttributeEditor
addButtonText="Add"
removeButtonText="Remove"
definition={[{ label: 'Key label', control: () => 'key' }, { control: () => 'value' }]}
items={[{}]}
gridLayout={[{ rows: [[1, 1]] }]}
/>
);
expect(warnOnce).toHaveBeenCalledWith(
'AttributeEditor',
'A `label` should be provided for each field definition. It is used as `aria-label` for accessibility.'
);
});
});