-
-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validate method to Expression/Constant
- Loading branch information
Showing
7 changed files
with
130 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { describe, test, expect } from 'vitest' | ||
import { Constant } from '../lib' | ||
|
||
describe('Constant', () => { | ||
describe('schema', () => { | ||
test('returns `{ type: "string" }` for string value', () => { | ||
expect(new Constant('string').schema).toEqual({ type: 'string' }) | ||
}) | ||
|
||
test('returns `{ type: "boolean" }` for boolean value', () => { | ||
expect(new Constant(true).schema).toEqual({ type: 'boolean' }) | ||
}) | ||
|
||
test('returns `{ type: "number" }` for number value', () => { | ||
expect(new Constant(42).schema).toEqual({ type: 'number' }) | ||
}) | ||
}) | ||
|
||
describe('validate', () => { | ||
test('returns true for valid value', () => { | ||
expect(new Constant(true).validate().valid).toBe(true) | ||
}) | ||
}) | ||
|
||
describe('matches', () => { | ||
test('returns true matching schema', () => { | ||
expect(new Constant(true).matches({ type: 'boolean' })).toBe(true) | ||
}) | ||
|
||
test('returns false for different schema', () => { | ||
expect(new Constant('string').matches({ type: 'boolean' })).toBe(false) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters