jeudi 20 février 2020

how to substitute null instead of strictly typed parameter of method for tests javascript

I have some method:

someMethod(userId: string): string {

 if(userId === null) {
   throw SomeError
 }

 ...
}

and test:

it('#someMetho with invalid parameters', () => {
        someMethod(null).catch((error: any) => {
           expect(error).toEqual(SomeError);
        });
    });

And got a warning that the Argument of type null is not assignable to parameter of type string.

How to avoid this warning in test?

Aucun commentaire:

Enregistrer un commentaire