File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { expect , test } from "vitest" ;
2
+ import dayjs from "dayjs" ;
3
+ import { generate } from "./schedule.ts" ;
4
+
5
+ const LIMIT_TO_PREVENT_INIFINITE_LOOPS = 1000 ;
6
+
7
+ test ( "generates first date closed to the start" , ( ) => {
8
+ const today = dayjs ( ) ;
9
+ for ( const date of generate ( { start : today } ) ) {
10
+ expect ( today <= date ) . toBe ( true ) ;
11
+ expect (
12
+ date < today . add ( 3 , "d" ) ,
13
+ `expect ${ date . format ( "YYYY-MM-DD" ) } is less than three days later (${ today . add ( 3 , "d" ) . format ( "YYYY-MM-DD" ) } )` ,
14
+ ) . toBe ( true ) ;
15
+ break ;
16
+ }
17
+ } ) ;
18
+
19
+ test ( "generates days only on Monday, Wednesday or Friday" , ( ) => {
20
+ let count = 0 ; // to prevent infinite loops
21
+ for ( const date of generate ( { } ) ) {
22
+ expect ( [ 1 , 3 , 5 ] ) . contain ( date . day ( ) ) ;
23
+ if ( count ++ > LIMIT_TO_PREVENT_INIFINITE_LOOPS ) {
24
+ break ;
25
+ }
26
+ }
27
+ } ) ;
You can’t perform that action at this time.
0 commit comments