question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validate doesn't work in Angular 9?

See original GitHub issue

Hi 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:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
marcjcommented, Mar 5, 2020

@ericjeker Yes, thought the same and already did move it up 😃

0reactions
ericjekercommented, Mar 5, 2020

Thanks, I will close this ticket.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found