Skip to content

Commit 339a335

Browse files
committed
Improved test coverage
1 parent 5af2ffa commit 339a335

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

src/core/test/pipes/pipes-model-parser.spec.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@ import * as sinon from "sinon";
22
import { expect } from "chai";
33
import { PipesModelParser } from "./../../pipes/pipes-model-parser";
44
import { ArgumentMetadata } from "@nestjs/common";
5+
import { IsString } from "class-validator";
56

67
class TestModel {
7-
constructor(public prop1: string, public prop2: number) {}
8+
constructor() {}
9+
@IsString()
10+
public prop1: string;
11+
12+
@IsString()
13+
public prop2: string;
814
}
915

1016
describe("PipesModelParser", () => {
1117
let target: PipesModelParser;
1218
let testModel;
19+
const metadata: ArgumentMetadata = {
20+
type: "body",
21+
metatype: TestModel,
22+
data: ""
23+
};
1324
beforeEach(() => {
1425
target = new PipesModelParser();
1526
});
@@ -24,16 +35,17 @@ describe("PipesModelParser", () => {
2435
});
2536
});
2637
describe("when metadata contains a class", () => {
27-
const metadata: ArgumentMetadata = {
28-
type: "body",
29-
metatype: TestModel,
30-
data: ""
31-
};
3238
it("should return an instance of the class", async () => {
3339
const testObj = { prop1: "value1", prop2: "value2" };
3440
const result = await target.transform(testObj, metadata);
3541
expect(result).to.be.instanceOf(TestModel);
3642
});
3743
});
44+
describe("when validation vails", () => {
45+
it("should throw an error", async () => {
46+
const testObj = { prop1: "value1" };
47+
return expect(target.transform(testObj, metadata)).to.be.rejected;
48+
});
49+
});
3850
});
3951
});

0 commit comments

Comments
 (0)