@@ -7,6 +7,7 @@ import type {
77 IsExact ,
88} from "https://deno.land/[email protected] /testing/types.ts" ; 99import is , {
10+ isAllOf ,
1011 isArray ,
1112 isArrayOf ,
1213 isBigInt ,
@@ -442,6 +443,45 @@ Deno.test("isOneOf<T>", async (t) => {
442443 } ) ;
443444} ) ;
444445
446+ Deno . test ( "isAllOf<T>" , async ( t ) => {
447+ await t . step ( "returns proper type predicate" , ( ) => {
448+ const preds = [
449+ is . ObjectOf ( { a : is . Number } ) ,
450+ is . ObjectOf ( { b : is . String } ) ,
451+ ] ;
452+ const a : unknown = { a : 0 , b : "a" } ;
453+ if ( isAllOf ( preds ) ( a ) ) {
454+ type _ = AssertTrue < IsExact < typeof a , { a : number ; b : string } > > ;
455+ }
456+ } ) ;
457+ await t . step ( "returns true on all of T" , ( ) => {
458+ const preds = [
459+ is . ObjectOf ( { a : is . Number } ) ,
460+ is . ObjectOf ( { b : is . String } ) ,
461+ ] ;
462+ assertEquals ( isAllOf ( preds ) ( { a : 0 , b : "a" } ) , true ) ;
463+ } ) ;
464+ await t . step ( "returns false on non of T" , async ( t ) => {
465+ const preds = [
466+ is . ObjectOf ( { a : is . Number } ) ,
467+ is . ObjectOf ( { b : is . String } ) ,
468+ ] ;
469+ assertEquals (
470+ isAllOf ( preds ) ( { a : 0 , b : 0 } ) ,
471+ false ,
472+ "Some properties has wrong type" ,
473+ ) ;
474+ assertEquals (
475+ isAllOf ( preds ) ( { a : 0 } ) ,
476+ false ,
477+ "Some properties does not exists" ,
478+ ) ;
479+ await testWithExamples ( t , isAllOf ( preds ) , {
480+ excludeExamples : [ "record" ] ,
481+ } ) ;
482+ } ) ;
483+ } ) ;
484+
445485Deno . test ( "isOptionalOf<T>" , async ( t ) => {
446486 await t . step ( "returns proper type predicate" , ( ) => {
447487 const a : unknown = undefined ;
0 commit comments