DEV Community

Pallat Anchaleechamaikorn
Pallat Anchaleechamaikorn

Posted on

4

Mocking ง่ายๆใน VSCode

เวลา dev ด้วย VSCode แล้วตอนจะลอง integrate test กับ service อื่นๆบนเครื่องตัวเอง วิธีที่ง่ายมากๆเลยคือใช้ extension ที่ชื่อ EasyMock

Alt Text

วิธีใช้ ให้ติดตั้ง extension ก่อน
จากนั้นเปิด Command Palette ขึ้นมาแล้วพิมพ์หา EasyMock

Alt Text

เลือก Run EasyMock โดย Default มันจะเปิด Browser ขึ้นมาแบบนี้ให้เอง

Alt Text

เท่านี้เราก็สามารถเริ่มใช้ EasyMock ได้แล้ว ซึ่งตัว Extension มันจะไปสร้าง example ให้ที่ ./mock/example.js ใน project ปัจจุบันนี้เลย โดยเราสามารถไปแก้ไขไฟล์ example.js โดยการกำหนดา path ที่จะให้เรียกเข้ามา แล้วก็ response ที่ต้องการ
โดยเบื้องต้นใน example.js ก็จะมีให้เรียกใช้เช่น

Alt Text

แบบนี้เวลาทดสอบงานก็ง่ายขึ้นเยอะเลย

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs