← React64 / 78
Filosofi RTL: Query by Role
React Testing Library (RTL) mendorong pencarian elemen berbasis peran aksesibilitas (getByRole('button')) daripada class name CSS.
👀 Contoh dulu
const button = screen.getByRole('button', { name: /kirim/i });Hasilnya: Mancari tombol dengan label 'kirim' di screen.
💡 Memastikan komponen ramah aksesibilitas untuk screen reader.
📝 Sekarang giliranmu
Tuliskan perintah RTL screen untuk mengambil elemen tombol di layar berdasarkan peran (role) aksesibilitasnya, lalu simpan di konstanta btn.
Preview