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

Proposal : migrate unit test to typescript #826

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"lint": "npm run lint_src && npm run lint_spec && npm run lint_perf",
"cover": "istanbul cover -x \"*-spec.js index.js *-helper.js spec/helpers/*\" ./node_modules/jasmine/bin/jasmine.js && npm run cover_remapping",
"cover_remapping": "remap-istanbul -i coverage/coverage.json -o coverage/coverage-remapped.json && remap-istanbul -i coverage/coverage.json -o coverage/coverage-remapped.lcov -t lcovonly && remap-istanbul -i coverage/coverage.json -o coverage/coverage-remapped -t html",
"test": "jasmine",
"test": "tsc --project ./spec --pretty && jasmine",
"watch": "watch \"echo triggering build && npm run build_test && echo build completed\" src -d -u -w=15",
"perf": "protractor protractor.conf.js",
"perf_micro": "node ./perf/micro/index.js",
Expand Down
39 changes: 0 additions & 39 deletions spec/helpers/marble-testing.js

This file was deleted.

41 changes: 41 additions & 0 deletions spec/helpers/marble-testing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
///<reference path='../../typings/jasmine/jasmine.d.ts'/>
import {Observable} from '../../dist/cjs/Observable';
import {SubscriptionLog} from '../../dist/cjs/testing/SubscriptionLog';
import {ColdObservable} from '../../dist/cjs/testing/ColdObservable';
import {HotObservable} from '../../dist/cjs/testing/HotObservable';
import {observableToBeFn, subscriptionLogsToBeFn} from '../../dist/cjs/testing/TestScheduler';

declare var global: any;

export function hot(marbles: string, values?: any, error?: any): HotObservable<any> {
if (!global.rxTestScheduler) {
throw 'tried to use hot() in async test';
}
return global.rxTestScheduler.createHotObservable.apply(global.rxTestScheduler, arguments);
}

export function cold(marbles: string, values?: any, error?: any): ColdObservable<any> {
if (!global.rxTestScheduler) {
throw 'tried to use cold() in async test';
}
return global.rxTestScheduler.createColdObservable.apply(global.rxTestScheduler, arguments);
}

export function expectObservable(observable: Observable<any>,
unsubscriptionMarbles: string = null): ({ toBe: observableToBeFn }) {
if (!global.rxTestScheduler) {
throw 'tried to use expectObservable() in async test';
}
return global.rxTestScheduler.expectObservable.apply(global.rxTestScheduler, arguments);
}

export function expectSubscriptions(actualSubscriptionLogs: SubscriptionLog[]): ({ toBe: subscriptionLogsToBeFn }) {
if (!global.rxTestScheduler) {
throw 'tried to use expectSubscriptions() in async test';
}
return global.rxTestScheduler.expectSubscriptions.apply(global.rxTestScheduler, arguments);
}

export function assertDeepEqual(actual, expected) {
(<any>expect(actual)).toDeepEqual(expected);
}
25 changes: 13 additions & 12 deletions spec/helpers/test-helper.js → spec/helpers/test-helper.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
///<reference path='../../typings/jasmine/jasmine.d.ts'/>
///<reference path='../../typings/lodash/lodash.d.ts'/>
declare var global: any;
declare var exports: any;
declare var module: any;
declare var Symbol: any;
declare var require: any;

//Fail timeouts faster
//Individual suites/specs should specify longer timeouts if needed.
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;

var _ = require('lodash');
var Rx = require('../../dist/cjs/Rx.KitchenSink');

var marbleHelpers = require('./marble-testing');
import * as _ from 'lodash';
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
import {assertDeepEqual} from './marble-testing';

global.rxTestScheduler = null;
global.cold = marbleHelpers.cold;
global.hot = marbleHelpers.hot;
global.expectObservable = marbleHelpers.expectObservable;
global.expectSubscriptions = marbleHelpers.expectSubscriptions;

var assertDeepEqual = marbleHelpers.assertDeepEqual;

var glit = global.it;
const glit = global.it;

global.it = function (description, cb, timeout) {
if (cb.length === 0) {
Expand Down Expand Up @@ -49,7 +50,7 @@ beforeEach(function () {
toDeepEqual: function (util, customEqualityTesters) {
return {
compare: function (actual, expected) {
var result = { pass: _.isEqual(actual, expected) };
let result: any = { pass: _.isEqual(actual, expected) };

if (!result.pass && Array.isArray(actual) && Array.isArray(expected)) {
result.message = 'Expected \n';
Expand Down
Loading