Validate doesn't work in Angular 9?
See original GitHub issueHi Marc,
I created a new project using Angular 9 and added the code for validation I found in the documentation. The test fails as no error is returned. I am wondering what am I doing wrong here? Am I missing something?
I understand that this may have something to do with Angular.
Repo with the code: https://github.com/ericjeker/marshal-validation
Steps:
ng new marshal-validation
npm install @marcj/marshal reflect-metadata
# create the page.spec.ts file
ng test
page.spec.ts
import {f, validate, ValidationError} from '@marcj/marshal';
class Page {
@f
name: string;
@f
age: number;
}
describe('Page', () => {
it('should fail', () => {
const errors = validate(Page, {name: 'peter'});
expect(errors.length).toBe(1);
expect(errors[0]).toBeInstanceOf(ValidationError);
expect(errors[0].path).toBe('age');
expect(errors[0].message).toBe('Required value is undefined');
});
it('should not fail', () => {
const errors = validate(Page, {name: 'gabriel', age: 42});
expect(errors.length).toBe(0);
});
});
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
The Validators And Errors Are Not Working In Angular 9
I have started working on Angular 9 and I am using the Reactive Form in Angular 9 but the problem is that the...
Read more >Validating form input - Angular
Every time the value of a form control changes, Angular runs validation and generates either a list of validation errors that results in...
Read more >First time validation doesn't show error · Issue #7558 · angular ...
BUG - First time validation doesn't show error until you tab out. Example: An input that only admits one digit (pattern[0-9]). First time:...
Read more >Angular Forms and Validations
We created this angular forms tutorial to help you learn everything about Angular forms validations in angular apps. These angular forms ...
Read more >Angular Validation - W3Schools
AngularJS offers client-side form validation. ... The field has been modified; $invalid The field content is not valid; $valid The field content is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ericjeker Yes, thought the same and already did move it up 😃
Thanks, I will close this ticket.