Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thenReject needs Type Error breaking change #150

Open
Larsrdev opened this issue Jul 23, 2019 · 4 comments
Open

thenReject needs Type Error breaking change #150

Larsrdev opened this issue Jul 23, 2019 · 4 comments

Comments

@Larsrdev
Copy link

Larsrdev commented Jul 23, 2019

Since Version 2.4.0 thenReject returns an Error and expecting an Error, but now tests like this are failing if the ErrorEntity is not like the Error (Property 'name' is missing in type 'ErrorEntity' but required in type 'Error'):

Some Class: 

registerAccount(mail: string, password: string) {
return new Promise<RegistrationEntity>((resolve, reject) => {
                this.MyService.makeRequest(request).then(() => {
                    resolve(new RegistrationEntity());
                }, (error) => {
                    reject(new ErrorEntity('some Error'));
                });
            });
}

The test: 
const errorEntity = instance(mock(ErrorEntity));
when(mockedRegistration.registerAccount('mail', 'password')).thenReject(errorEntity);

Here: https://github.com/NagRock/ts-mockito/blob/v2.4.0/src/MethodStubSetter.ts

Its a really bad way to pretend, that every rejection has to be an Error Object.

@mousedownmike
Copy link

According to this MS Typescript issue #7588 (If I follow it correctly) reject should support any type and it looks like it's only typed to Error in the MethodStubSetter (i.e. RejectPromiseMethodStub seems OK with any).

I'm new here, so I might be missing something. Is there a benefit to requiring thenReject to receive a type of Error?

@Larsrdev
Copy link
Author

No there isn't any benefit, The restriction came with Version 2.4.0. It would be great to support any as rejection type. @NagRock

@cornr
Copy link

cornr commented Jul 24, 2020

@NagRock any news on this one?
We rely heavily on rejecting with any types. This issue prevents us from updating to the latest ts-mockito version which now includes a needed bugfix.

@cornr
Copy link

cornr commented Jul 24, 2020

I fixed this issue in #199. @NagRock please have a look at my first PR to ts-mockito 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants