Snapshot testing จับ "snapshot" ของเอาต์พุตบางอย่าง (โดยทั่วไปคือเอาต์พุตที่ render ของ UI component หรือโครงสร้างข้อมูล) และเปรียบเทียบการรันในอนาคตกับมัน — แจ้งเตือนเมื่อเอาต์พุตเปลี่ยน มันมีประโยชน์ในการตรวจจับการเปลี่ยนแปลงที่ไม่ตั้งใจ แต่มีข้อจำกัดที่ต้องเข้าใจ
Snapshot testing ทำงานอย่างไร
1. First run → the test RECORDS the output (e.g. a rendered component) as a SNAPSHOT file
2. Later runs → COMPARE the current output to the saved snapshot:
→ MATCHES → pass; DIFFERS → fail (the output changed)
3. If the change is INTENTIONAL → UPDATE the snapshot (review the diff, then accept)
(, {
tree = ().();
(tree).();
});
