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

test(dtslint): add dtslint test on count operator (#4093) #4139

Merged
merged 1 commit into from
Sep 18, 2018

Conversation

dkosasih
Copy link
Contributor

Description: Add count dtslint test

Related issue (if exists): #4093

import { count } from 'rxjs/operators';

it('should always infer number', () => {
const o = of(1, 2, 3).pipe(count(x => x > 1)); // $ExpectType Observable<number>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should also test the predicate overloads.

predicate: (value: T, index: number, source: Observable<T>)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added few more tests around the predicate overloads types.
Please let me know if they are of a good value.
Thanks

});

it('should expect function parameter', () => {
const o = of(1, 2, 3).pipe(count(9)); // $ExpectError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also test if the value is the same type as the source.
For example

const o = of(1, 2, 3).pipe(count((value: string) => value !== ''); // $ExpectError

@coveralls
Copy link

coveralls commented Sep 15, 2018

Coverage Status

Coverage remained the same at 96.809% when pulling 6267245 on dkosasih:dtslint-count into d032804 on ReactiveX:master.

import { count, buffer } from 'rxjs/operators';

it('should always infer number', () => {
const o = of(1, 2, 3).pipe(count(x => x > 1)); // $ExpectType Observable<number>
Copy link
Collaborator

@cartant cartant Sep 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With count, the return type of the piped observable will always be Observable<number>, so I think that for at least one of the tests, the source observable type should be something other than number - to make sure that the output type comes from the count operator and not the source. E.g.:

const o = of('1', '2', '3').pipe(count(x => x !== '1')); // $ExpectType Observable<number>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cartant I have added another row to both number or string will always return number

Copy link
Collaborator

@cartant cartant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cartant cartant merged commit ea27916 into ReactiveX:master Sep 18, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Oct 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants