@@ -2,6 +2,17 @@ import { TypeFactories } from "../../../src/lib/helpers/TypeFactories";
22
33import assert from "assert" ;
44
5+ class CustomError extends Error {
6+
7+ public constructor ( message ?: string ) {
8+ super ( message ) ;
9+
10+ this . name = this . constructor . name ;
11+ Error . captureStackTrace ( this , this . constructor ) ;
12+ Object . setPrototypeOf ( this , CustomError . prototype ) ;
13+ }
14+ }
15+
516describe ( "[Unit] TypeFactories.test.ts" , ( ) => {
617 describe ( ".predicate" , ( ) => {
718 describe ( "#Boolean" , ( ) => {
@@ -42,6 +53,24 @@ describe("[Unit] TypeFactories.test.ts", () => {
4253 } ) ;
4354 } ) ;
4455
56+ describe ( "#Error" , ( ) => {
57+ context ( "when the value is an Error" , ( ) => {
58+ it ( "returns true" , ( ) => {
59+ const result = TypeFactories . Error . predicate ( new Error ( "foo" ) ) ;
60+
61+ assert . equal ( result , true ) ;
62+ } ) ;
63+ } ) ;
64+
65+ context ( "when the value is not an Error" , ( ) => {
66+ it ( "returns false" , ( ) => {
67+ const result = TypeFactories . Error . predicate ( "foo" ) ;
68+
69+ assert . equal ( result , false ) ;
70+ } ) ;
71+ } ) ;
72+ } ) ;
73+
4574 describe ( "#Function" , ( ) => {
4675 context ( "when the value is a function" , ( ) => {
4776 it ( "returns true" , ( ) => {
@@ -143,6 +172,24 @@ describe("[Unit] TypeFactories.test.ts", () => {
143172 } ) ;
144173 } ) ;
145174
175+ describe ( ".error" , ( ) => {
176+ context ( "when the value is an instace o the error type" , ( ) => {
177+ it ( "returns true" , ( ) => {
178+ const result = TypeFactories . error ( CustomError ) . predicate ( new CustomError ( "foo" ) ) ;
179+
180+ assert . equal ( result , true ) ;
181+ } ) ;
182+ } ) ;
183+
184+ context ( "when the value is not an instace o the error type" , ( ) => {
185+ it ( "returns false" , ( ) => {
186+ const result = TypeFactories . error ( CustomError ) . predicate ( new Error ( "foo" ) ) ;
187+
188+ assert . equal ( result , false ) ;
189+ } ) ;
190+ } ) ;
191+ } ) ;
192+
146193 describe ( ".instanceOf" , ( ) => {
147194 context ( "when the value is an instance of the passed type" , ( ) => {
148195 it ( "returns true" , ( ) => {
0 commit comments