11import { describe , expect , it } from 'vitest'
22
3- import { boolean , parse , safeParse } from '../../index'
3+ import { boolean } from '../../index'
44
55describe ( 'boolean schema' , ( ) => {
66 it ( 'accepts boolean values' , async ( ) => {
77 const schema = boolean ( )
88
9- await expect ( parse ( schema , true ) ) . resolves . toBe ( true )
10- await expect ( parse ( schema , false ) ) . resolves . toBe ( false )
9+ await expect ( schema . parse ( true ) ) . resolves . toBe ( true )
10+ await expect ( schema . parse ( false ) ) . resolves . toBe ( false )
1111 } )
1212
1313 it ( 'rejects non-boolean values' , async ( ) => {
1414 const schema = boolean ( )
15- const report = await safeParse ( schema , 'not-boolean' )
15+ const report = await schema . safeParse ( 'not-boolean' )
1616
1717 expect ( report . passed ) . toBe ( false )
1818 expect ( 'value' in report ) . toBe ( false )
@@ -21,22 +21,22 @@ describe('boolean schema', () => {
2121 it ( 'supports optional modifier' , async ( ) => {
2222 const schema = boolean ( ) . optional ( )
2323
24- const hit = await safeParse ( schema , true )
24+ const hit = await schema . safeParse ( true )
2525 expect ( hit . passed ) . toBe ( true )
2626 expect ( hit . value ) . toBe ( true )
2727
28- const optionalReport = await safeParse ( schema , undefined )
28+ const optionalReport = await schema . safeParse ( undefined )
2929 expect ( optionalReport . passed ) . toBe ( true )
3030 expect ( optionalReport . value ) . toBeUndefined ( )
3131
32- const nullReport = await safeParse ( schema , null )
32+ const nullReport = await schema . safeParse ( null )
3333 expect ( nullReport . passed ) . toBe ( false )
3434 } )
3535
3636 it ( 'supports exactOptional modifier' , async ( ) => {
3737 const schema = boolean ( ) . exactOptional ( )
3838
39- const report = await safeParse ( schema , undefined )
39+ const report = await schema . safeParse ( undefined )
4040 expect ( report . passed ) . toBe ( true )
4141 if ( report . passed ) {
4242 expect ( report . value ) . toBeUndefined ( )
@@ -46,68 +46,68 @@ describe('boolean schema', () => {
4646 it ( 'supports undefinable modifier' , async ( ) => {
4747 const schema = boolean ( ) . undefinable ( )
4848
49- const undefReport = await safeParse ( schema , undefined )
49+ const undefReport = await schema . safeParse ( undefined )
5050 expect ( undefReport . passed ) . toBe ( true )
5151 expect ( undefReport . value ) . toBeUndefined ( )
5252
53- const nullReport = await safeParse ( schema , null )
53+ const nullReport = await schema . safeParse ( null )
5454 expect ( nullReport . passed ) . toBe ( false )
5555 } )
5656
5757 it ( 'supports nullable modifier' , async ( ) => {
5858 const schema = boolean ( ) . nullable ( )
5959
60- const nullReport = await safeParse ( schema , null )
60+ const nullReport = await schema . safeParse ( null )
6161 expect ( nullReport . passed ) . toBe ( true )
6262 expect ( nullReport . value ) . toBeNull ( )
6363
64- const undefinedReport = await safeParse ( schema , undefined )
64+ const undefinedReport = await schema . safeParse ( undefined )
6565 expect ( undefinedReport . passed ) . toBe ( false )
6666 } )
6767
6868 it ( 'supports nullish modifier' , async ( ) => {
6969 const schema = boolean ( ) . nullish ( )
7070
71- const undefinedReport = await safeParse ( schema , undefined )
71+ const undefinedReport = await schema . safeParse ( undefined )
7272 expect ( undefinedReport . passed ) . toBe ( true )
7373 expect ( undefinedReport . value ) . toBeUndefined ( )
7474
75- const nullReport = await safeParse ( schema , null )
75+ const nullReport = await schema . safeParse ( null )
7676 expect ( nullReport . passed ) . toBe ( true )
7777 expect ( nullReport . value ) . toBeNull ( )
7878 } )
7979
8080 it ( 'supports default modifier' , async ( ) => {
8181 const schema = boolean ( ) . default ( true )
8282
83- await expect ( parse ( schema , undefined ) ) . resolves . toBe ( true )
84- await expect ( parse ( schema , null ) ) . resolves . toBe ( true )
85- await expect ( parse ( schema , false ) ) . resolves . toBe ( false )
83+ await expect ( schema . parse ( undefined ) ) . resolves . toBe ( true )
84+ await expect ( schema . parse ( null ) ) . resolves . toBe ( true )
85+ await expect ( schema . parse ( false ) ) . resolves . toBe ( false )
8686 } )
8787
8888 it ( 'applies required after optional' , async ( ) => {
8989 const schema = boolean ( ) . optional ( ) . required ( )
9090
91- const report = await safeParse ( schema , undefined )
91+ const report = await schema . safeParse ( undefined )
9292 expect ( report . passed ) . toBe ( false )
9393 } )
9494
9595 it ( 'uses last optionality modifier wins semantics' , async ( ) => {
9696 const optionalThenNullable = boolean ( ) . optional ( ) . nullable ( )
9797 const nullableThenOptional = boolean ( ) . nullable ( ) . optional ( )
9898
99- const optionalThenNullableNull = await safeParse ( optionalThenNullable , null )
99+ const optionalThenNullableNull = await optionalThenNullable . safeParse ( null )
100100 expect ( optionalThenNullableNull . passed ) . toBe ( true )
101101 expect ( optionalThenNullableNull . value ) . toBeNull ( )
102102
103- const optionalThenNullableUndefined = await safeParse ( optionalThenNullable , undefined )
103+ const optionalThenNullableUndefined = await optionalThenNullable . safeParse ( undefined )
104104 expect ( optionalThenNullableUndefined . passed ) . toBe ( false )
105105
106- const nullableThenOptionalUndefined = await safeParse ( nullableThenOptional , undefined )
106+ const nullableThenOptionalUndefined = await nullableThenOptional . safeParse ( undefined )
107107 expect ( nullableThenOptionalUndefined . passed ) . toBe ( true )
108108 expect ( nullableThenOptionalUndefined . value ) . toBeUndefined ( )
109109
110- const nullableThenOptionalNull = await safeParse ( nullableThenOptional , null )
110+ const nullableThenOptionalNull = await nullableThenOptional . safeParse ( null )
111111 expect ( nullableThenOptionalNull . passed ) . toBe ( false )
112112 } )
113113} )
0 commit comments