-
I want to use construction like this. pipe(
data,
E.fold(absurd, response => {
expect(response.uid).toBe('uid');
expect(response.email).toBe('mail@mail.mail');
expect(response.role).toBe('user');
verify(mockedFirebaseAuth.getUser('uid')).called();
verify(
mockedFirebaseAuth.setCustomUserClaims('uid', anything()),
).called();
}),
); But TS error on typing My answer is: Is there possibility to use |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I used often this construction in test, but after more strict changes in tsconfig has this errors. expect(E.isRight(data)).toBe(true);
if (E.isRight(data)) {
expect(data.right.uid).toBe('uid');
expect(data.right.email).toBe('mail@mail.mail');
expect(data.right.role).toBe('user');
verify(mockedFirebaseAuth.getUser('uid')).called();
verify(
mockedFirebaseAuth.setCustomUserClaims('uid', anything()),
).called();
} But sometimes I like more to use |
Beta Was this translation helpful? Give feedback.
-
You can test the shape of the whole thing inside the constructor: expect(data).toEqual(E.right({
uid: 'uid',
email: 'mail@mail.mail',
role: 'user',
})) Or use something like unsafeUnwrap, which is mildly more ergonomic than |
Beta Was this translation helpful? Give feedback.
You can test the shape of the whole thing inside the constructor:
Or use something like unsafeUnwrap, which is mildly more ergonomic than
isRight
; throwing an error is fine in the context of testing.