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

chore(test): start fixing test types #3680

Merged
merged 5 commits into from May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -31,6 +31,7 @@ install:

script:
- if [ "$FULL_VALIDATE" == "true" ] && [ -n "DANGER_GITHUB_API_TOKEN" ]; then echo {} > ./.babelrc && npx danger; fi
- npm run test_check
- npm test
- npm run test:systemjs

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -86,6 +86,7 @@
"prepublish": "shx rm -rf ./typings && npm run build_all",
"publish_docs": "./publish_docs.sh",
"test": "cross-env TS_NODE_PROJECT=spec/tsconfig.json mocha --opts spec/support/default.opts \"spec/**/*-spec.ts\"",
"test_check": "tsc --project ./spec/tsconfig.check.json",
"test:browser": "echo \"Browser test is not working currently\" && exit -1 && npm-run-all build:spec:browser && opn spec/support/mocha-browser-runner.html",
"test:cover": "nyc npm test",
"test:circular": "dependency-cruise --validate .dependency-cruiser.json -x \"^node_modules\" dist/esm5",
Expand Down
2 changes: 1 addition & 1 deletion spec/Notification-spec.ts
Expand Up @@ -162,7 +162,7 @@ describe('Notification', () => {

it('should accept observer for error Notification', () => {
let observed = false;
const n = Notification.createError();
const n = Notification.createError<string>();
const observer = Rx.Subscriber.create((x: string) => {
throw 'should not be called';
}, (err: any) => {
Expand Down
2 changes: 1 addition & 1 deletion spec/Observable-spec.ts
Expand Up @@ -85,7 +85,7 @@ describe('Observable', () => {
Rx.config.Promise = function MyPromise(callback: any) {
wasCalled = true;
return new Promise<number>(callback);
};
} as any;

Observable.of(42).forEach((x) => {
expect(x).to.equal(42);
Expand Down
25 changes: 12 additions & 13 deletions spec/Scheduler-spec.ts
@@ -1,17 +1,16 @@
import { expect } from 'chai';
import * as Rx from 'rxjs/Rx';

const Scheduler = Rx.Scheduler;
import { queueScheduler as queue } from 'rxjs';
import { QueueScheduler } from 'rxjs/internal/scheduler/QueueScheduler';

/** @test {Scheduler} */
describe('Scheduler.queue', () => {
it('should schedule things recursively', () => {
let call1 = false;
let call2 = false;
Scheduler.queue.active = false;
Scheduler.queue.schedule(() => {
(queue as QueueScheduler).active = false;
queue.schedule(() => {
call1 = true;
Scheduler.queue.schedule(() => {
queue.schedule(() => {
call2 = true;
});
});
Expand All @@ -22,8 +21,8 @@ describe('Scheduler.queue', () => {
it('should schedule things recursively via this.schedule', () => {
let call1 = false;
let call2 = false;
Scheduler.queue.active = false;
Scheduler.queue.schedule(function (state) {
(queue as QueueScheduler).active = false;
queue.schedule(function (state) {
call1 = state.call1;
call2 = state.call2;
if (!call2) {
Expand All @@ -36,7 +35,7 @@ describe('Scheduler.queue', () => {

it('should schedule things in the future too', (done: MochaDone) => {
let called = false;
Scheduler.queue.schedule(() => {
queue.schedule(() => {
called = true;
}, 60);

Expand All @@ -51,20 +50,20 @@ describe('Scheduler.queue', () => {
});

it('should be reusable after an error is thrown during execution', (done: MochaDone) => {
const results = [];
const results: number[] = [];

expect(() => {
Scheduler.queue.schedule(() => {
queue.schedule(() => {
results.push(1);
});

Scheduler.queue.schedule(() => {
queue.schedule(() => {
throw new Error('bad');
});
}).to.throw(Error, 'bad');

setTimeout(() => {
Scheduler.queue.schedule(() => {
queue.schedule(() => {
results.push(2);
done();
});
Expand Down
80 changes: 40 additions & 40 deletions spec/Subject-spec.ts
Expand Up @@ -8,7 +8,7 @@ const Observable = Rx.Observable;
/** @test {Subject} */
describe('Subject', () => {
it('should pump values right on through itself', (done: MochaDone) => {
const subject = new Subject();
const subject = new Subject<string>();
const expected = ['foo', 'bar'];

subject.subscribe((x: string) => {
Expand All @@ -21,7 +21,7 @@ describe('Subject', () => {
});

it('should pump values to multiple subscribers', (done: MochaDone) => {
const subject = new Subject();
const subject = new Subject<string>();
const expected = ['foo', 'bar'];

let i = 0;
Expand All @@ -43,10 +43,10 @@ describe('Subject', () => {

it('should handle subscribers that arrive and leave at different times, ' +
'subject does not complete', () => {
const subject = new Subject();
const results1 = [];
const results2 = [];
const results3 = [];
const subject = new Subject<number>();
const results1: (number | string)[] = [];
const results2: (number | string)[] = [];
const results3: (number | string)[] = [];

subject.next(1);
subject.next(2);
Expand Down Expand Up @@ -96,10 +96,10 @@ describe('Subject', () => {

it('should handle subscribers that arrive and leave at different times, ' +
'subject completes', () => {
const subject = new Subject();
const results1 = [];
const results2 = [];
const results3 = [];
const subject = new Subject<number>();
const results1: (number | string)[] = [];
const results2: (number | string)[] = [];
const results3: (number | string)[] = [];

subject.next(1);
subject.next(2);
Expand Down Expand Up @@ -144,10 +144,10 @@ describe('Subject', () => {

it('should handle subscribers that arrive and leave at different times, ' +
'subject terminates with an error', () => {
const subject = new Subject();
const results1 = [];
const results2 = [];
const results3 = [];
const subject = new Subject<number>();
const results1: (number | string)[] = [];
const results2: (number | string)[] = [];
const results3: (number | string)[] = [];

subject.next(1);
subject.next(2);
Expand Down Expand Up @@ -192,10 +192,10 @@ describe('Subject', () => {

it('should handle subscribers that arrive and leave at different times, ' +
'subject completes before nexting any value', () => {
const subject = new Subject();
const results1 = [];
const results2 = [];
const results3 = [];
const subject = new Subject<number>();
const results1: (number | string)[] = [];
const results2: (number | string)[] = [];
const results3: (number | string)[] = [];

const subscription1 = subject.subscribe(
function (x) { results1.push(x); },
Expand Down Expand Up @@ -229,10 +229,10 @@ describe('Subject', () => {
});

it('should disallow new subscriber once subject has been disposed', () => {
const subject = new Subject();
const results1 = [];
const results2 = [];
const results3 = [];
const subject = new Subject<number>();
const results1: (number | string)[] = [];
const results2: (number | string)[] = [];
const results3: (number | string)[] = [];

const subscription1 = subject.subscribe(
function (x) { results1.push(x); },
Expand Down Expand Up @@ -307,31 +307,31 @@ describe('Subject', () => {
it('should have a static create function that works', () => {
expect(Subject.create).to.be.a('function');
const source = Observable.of(1, 2, 3, 4, 5);
const nexts = [];
const output = [];
const nexts: number[] = [];
const output: number[] = [];

let error: any;
let complete = false;
let outputComplete = false;

const destination = {
closed: false,
next: function (x) {
next: function (x: number) {
nexts.push(x);
},
error: function (err) {
error: function (err: any) {
error = err;
this.closed = true;
},
complete: () => {
complete: function () {
complete = true;
this.closed = true;
}
};

const sub = Subject.create(destination, source);

sub.subscribe(function (x) {
sub.subscribe(function (x: number) {
output.push(x);
}, null, () => {
outputComplete = true;
Expand All @@ -353,31 +353,31 @@ describe('Subject', () => {
it('should have a static create function that works also to raise errors', () => {
expect(Subject.create).to.be.a('function');
const source = Observable.of(1, 2, 3, 4, 5);
const nexts = [];
const output = [];
const nexts: number[] = [];
const output: number[] = [];

let error: any;
let complete = false;
let outputComplete = false;

const destination = {
closed: false,
next: function (x) {
next: function (x: number) {
nexts.push(x);
},
error: function (err) {
error: function (err: any) {
error = err;
this.closed = true;
},
complete: () => {
complete: function () {
complete = true;
this.closed = true;
}
};

const sub = Subject.create(destination, source);

sub.subscribe(function (x) {
sub.subscribe(function (x: number) {
output.push(x);
}, null, () => {
outputComplete = true;
Expand Down Expand Up @@ -449,8 +449,8 @@ describe('Subject', () => {
});

it('should not next after completed', () => {
const subject = new Rx.Subject();
const results = [];
const subject = new Rx.Subject<string>();
const results: string[] = [];
subject.subscribe(x => results.push(x), null, () => results.push('C'));
subject.next('a');
subject.complete();
Expand All @@ -460,8 +460,8 @@ describe('Subject', () => {

it('should not next after error', () => {
const error = new Error('wut?');
const subject = new Rx.Subject();
const results = [];
const subject = new Rx.Subject<string>();
const results: string[] = [];
subject.subscribe(x => results.push(x), (err) => results.push(err));
subject.next('a');
subject.error(error);
Expand Down Expand Up @@ -508,8 +508,8 @@ describe('Subject', () => {
});

it('should work with inherited subject', () => {
const results = [];
const subject = new Rx.AsyncSubject();
const results: (number | string)[] = [];
const subject = new Rx.AsyncSubject<number>();

subject.next(42);
subject.complete();
Expand Down
2 changes: 2 additions & 0 deletions spec/helpers/tests2png/painter.ts
@@ -1,5 +1,7 @@
/*eslint-disable no-param-reassign, no-use-before-define*/
// @ts-ignore
import * as gm from 'gm';
// @ts-ignore
import * as Color from 'color';
import { cloneDeep, isEqual} from 'lodash';
import { TestMessage } from '../../../src/internal/testing/TestMessage';
Expand Down
16 changes: 16 additions & 0 deletions spec/tsconfig.check.json
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"noEmit": true
},
"extends": "../tsconfig.json",
"include": [
"./*.ts",
"./ajax/**/*.ts",
"./helpers/**/*.ts",
"./migration/**/*.ts",
"./symbol/**/*.ts",
"./testing/**/*.ts",
"./util/**/*.ts",
"./websocket/**/*.ts"
]
}