Nestia E2E Helper
Helper library for E2E testing in NestJS.
With @nestia/e2e
, you can easily validate your NestJS server through E2E testing.
import {
ArrayUtil,
GaffComparator,
RandomGenerator,
TestValidator,
} from "@nestia/e2e";
import typia from "typia";
import api from "@samchon/bbs-api/lib/index";
import { IBbsArticle } from "@samchon/bbs-api/lib/structures/bbs/IBbsArticle";
import { IPage } from "@samchon/bbs-api/lib/structures/common/IPage";
export async function test_api_bbs_article_index_sort(
connection: api.IConnection,
): Promise<void> {
const section: string = "general";
const articles: IBbsArticle[] = await ArrayUtil.asyncRepeat(100, () =>
api.functional.bbs.articles.store(connection, section, {
writer: RandomGenerator.name(),
title: RandomGenerator.paragraph(5)(),
body: RandomGenerator.content(8)()(),
format: "txt",
files: [],
password: RandomGenerator.alphabets(8),
}),
);
typia.assertEquals(articles);
const validator = TestValidator.sort("BbsArticleProvider.index()")(
async (
sort: IPage.IRequest.Sort<IBbsArticle.IRequest.SortableColumns>,
) => {
const page: IPage<IBbsArticle.ISummary> =
await api.functional.bbs.articles.index(connection, section, {
limit: 100,
sort,
});
return typia.assertEquals(page).data;
},
);
const components = [
validator("created_at")(GaffComparator.dates((x) => x.created_at)),
validator("updated_at")(GaffComparator.dates((x) => x.updated_at)),
validator("title")(GaffComparator.strings((x) => x.title)),
validator("writer")(GaffComparator.strings((x) => x.writer)),
validator(
"writer",
"title",
)(GaffComparator.strings((x) => [x.writer, x.title])),
];
for (const comp of components) {
await comp("+", false);
await comp("-", false);
}
}
Setup
npm install --save-dev @nestia/e2e
Just setup with npm command, that's all.
For referece, due to test program would not be published, I rcommend to install as dev
mode.
Features
About supported features, read descriptive comments of below: