11import * as React from 'react' ;
22import expect from 'expect' ;
33import { ChipField } from './ChipField' ;
4- import { render } from '@testing-library/react' ;
4+ import { render , screen } from '@testing-library/react' ;
55import { RecordContextProvider , I18nContextProvider } from 'ra-core' ;
66import polyglotI18nProvider from 'ra-i18n-polyglot' ;
77
@@ -25,49 +25,59 @@ const i18nProvider = polyglotI18nProvider(
2525) ;
2626
2727describe ( '<ChipField />' , ( ) => {
28- it ( 'should display the record value added as source' , ( ) => {
29- const { getByText } = render (
30- < ChipField source = "name" record = { { id : 123 , name : 'foo' } } />
31- ) ;
32- expect ( getByText ( 'foo' ) ) . not . toBeNull ( ) ;
28+ it ( 'should display the record value added as source' , async ( ) => {
29+ render ( < ChipField source = "name" record = { { id : 123 , name : 'foo' } } /> ) ;
30+ await screen . findByText ( 'foo' ) ;
3331 } ) ;
3432
35- it ( 'should use record from RecordContext' , ( ) => {
36- const { getByText } = render (
33+ it ( 'should use record from RecordContext' , async ( ) => {
34+ render (
3735 < RecordContextProvider value = { { id : 123 , name : 'foo' } } >
3836 < ChipField source = "name" />
3937 </ RecordContextProvider >
4038 ) ;
41- expect ( getByText ( 'foo' ) ) . not . toBeNull ( ) ;
39+ await screen . findByText ( 'foo' ) ;
4240 } ) ;
4341
44- it ( 'should not display any label added as props' , ( ) => {
45- const { getByText } = render (
42+ it ( 'should not display any label added as props' , async ( ) => {
43+ render (
4644 < ChipField
4745 source = "name"
4846 record = { { id : 123 , name : 'foo' } }
4947 label = "bar"
5048 />
5149 ) ;
52- expect ( getByText ( 'foo' ) ) . not . toBeNull ( ) ;
50+ await screen . findByText ( 'foo' ) ;
5351 } ) ;
5452
5553 it . each ( [ null , undefined ] ) (
5654 'should render the emptyText when value is %s' ,
57- name => {
58- const { getByText } = render (
55+ async name => {
56+ render (
5957 < ChipField
6058 source = "name"
6159 record = { { id : 123 , name } }
6260 emptyText = "NA"
6361 />
6462 ) ;
65- expect ( getByText ( 'NA' ) ) . not . toBeNull ( ) ;
63+ await screen . findByText ( 'NA' ) ;
6664 }
6765 ) ;
6866
69- it ( 'should translate emptyText' , ( ) => {
70- const { getByText } = render (
67+ it ( 'should not render the emptyText when value is zero' , async ( ) => {
68+ render (
69+ < ChipField
70+ source = "name"
71+ record = { { id : 123 , name : 0 } }
72+ emptyText = "NA"
73+ />
74+ ) ;
75+
76+ expect ( screen . queryByText ( 'NA' ) ) . toBeNull ( ) ;
77+ } ) ;
78+
79+ it ( 'should translate emptyText' , async ( ) => {
80+ render (
7181 < I18nContextProvider value = { i18nProvider } >
7282 < ChipField
7383 record = { { id : 123 } }
@@ -78,7 +88,7 @@ describe('<ChipField />', () => {
7888 </ I18nContextProvider >
7989 ) ;
8090
81- expect ( getByText ( 'Not found' ) ) . not . toBeNull ( ) ;
91+ await screen . findByText ( 'Not found' ) ;
8292 } ) ;
8393
8494 it ( 'should return null when value and emptyText are an empty string' , ( ) => {
@@ -92,15 +102,15 @@ describe('<ChipField />', () => {
92102 expect ( container . firstChild ) . toBeNull ( ) ;
93103 } ) ;
94104
95- it ( 'should display the emptyText when value is an empty string' , ( ) => {
96- const { getByText } = render (
105+ it ( 'should display the emptyText when value is an empty string' , async ( ) => {
106+ render (
97107 < ChipField
98108 source = "name"
99109 record = { { id : 123 , name : '' } }
100110 emptyText = "NA"
101111 />
102112 ) ;
103- expect ( getByText ( 'NA' ) ) . not . toBeNull ( ) ;
113+ await screen . findByText ( 'NA' ) ;
104114 } ) ;
105115
106116 it ( 'should return null when value is an empty string and emptyText is null' , ( ) => {
0 commit comments