我有以下反應組件import styles from './Alert.module.scss';const Alert = ({ role = 'document', type = 'info',}) => (<GridItem> <div className={`${styles.alert} ${styles[`alert-${type}`]}`} role={role}> {icon && <div className={`${styles['alert-icon']}`} />} <div className={styles.content}>{children}</div> </div></GridItem>我正在這樣寫我的測試jest.mock('./Alert.module.scss', () => ({ 'alert': 'alert', 'type': 'info',}));jest.mock('./GridItem', () => 'GridItem');describe('Alert', () => { it('should render correctly', () => { expect(renderer.create(<Alert>Alert</Alert>)).toMatchSnapshot(); });});問題是在創建快照時,類型變量返回未定義。我假設它與字符串連接有關,因為“角色”變量寫入正確。這是快照。<GridItem> <div className="alert undefined" role="document" > <div> Alert </div> </div></GridItem>`;所以,我不確定我在這里遺漏了什么,或者是否對字符串連接有任何限制。我怎樣才能正確得到它?謝謝!
在 Jest 測試快照上返回未定義的字符串連接
肥皂起泡泡
2023-05-19 17:18:34