๐ฆ NestJs ์ธ์คํจํ๋ฉด JEST ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๋ ๊ฒ ๋ค ์ค์น๋์ด์๋ค ๋๋ฐ ...
์ ๊ธฐ์์ ์ฐ๋ฆฌ๋ watch ๋ฅผ ์ฐ๊ณ ๋ง์ง๋ง์๋ cov ๋ก ๋ด๋ณผ์์ ์ด๋ค.
CRUD ์ ๋ํ ์คํธ๋ ์ด๋์ ๋ ํด๋ดค์๊ฑฐ๋ผ๊ณ ์๊ฐํ๊ณ ๊ฐ๋จํ ์์๋ง ์ ์ด๋ณด๊ฒ ๋ค.
nest g service users
describe("getOne", () => {
it("should return a movie", () => {
service.create({
title: "Test Movie",
genres: ["Test"],
year: 2023,
});
const movie = service.getOne(1);
expect(movie).toBeDefined();
expect(movie.id).toEqual(1);
expect(movie.title).toEqual("Test Movie");
})
it("should throw 404 error", () => {
try{
service.getOne(999);
}catch(e){
expect(e).toBeInstanceOf(NotFoundException)
expect(e.message).toEqual("Movie with ID 999 not found.")
}
})
})
expect(movie.title).toEqual("Test Movi");
์ด๋ฐ์์ผ๋ก CRUD ์ ๋ ํ ์คํธ๋ฅผ ์งํํ๋ฉด ๋๋ค. ์งํํ๊ฒ ๋๋ฉด ~