Skip to content

Commit

Permalink
Jest jasmine/ts migration (#7970)
Browse files Browse the repository at this point in the history
  • Loading branch information
doniyor2109 authored and SimenB committed Mar 5, 2019
1 parent d23f1ef commit 7a4ee21
Show file tree
Hide file tree
Showing 54 changed files with 2,331 additions and 1,911 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -37,6 +37,7 @@

### Chore & Maintenance

- `[jest-jasmine2]`: TS migration ([#7970](https://github.com/facebook/jest/pull/7970))
- `[jest-each]`: Refactor into multiple files with better types ([#8018](https://github.com/facebook/jest/pull/8018))
- `[jest-each]`: Migrate to Typescript ([#8007](https://github.com/facebook/jest/pull/8007))
- `[jest-environment-jsdom]`: Migrate to TypeScript ([#7985](https://github.com/facebook/jest/pull/8003))
Expand Down
8 changes: 5 additions & 3 deletions packages/jest-jasmine2/package.json
Expand Up @@ -8,24 +8,26 @@
},
"license": "MIT",
"main": "build/index.js",
"types": "build/index.d.ts",
"dependencies": {
"@babel/traverse": "^7.1.0",
"@jest/environment": "^24.1.0",
"@jest/types": "^24.1.0",
"chalk": "^2.0.1",
"co": "^4.6.0",
"expect": "^24.1.0",
"is-generator-fn": "^2.0.0",
"jest-each": "^24.0.0",
"jest-matcher-utils": "^24.0.0",
"jest-message-util": "^24.0.0",
"jest-runtime": "^24.1.0",
"jest-snapshot": "^24.1.0",
"jest-util": "^24.0.0",
"pretty-format": "^24.0.0",
"throat": "^4.0.0"
},
"devDependencies": {
"@types/babel__traverse": "^7.0.4",
"jest-diff": "^24.0.0",
"jest-runtime": "^24.1.0"
"@types/babel__traverse": "^7.0.4"
},
"engines": {
"node": ">= 6"
Expand Down
Expand Up @@ -3,8 +3,6 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export default class ExpectationFailed extends Error {}
7 changes: 6 additions & 1 deletion packages/jest-jasmine2/src/PCancelable.js
@@ -1,4 +1,9 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

Expand Down
Expand Up @@ -6,21 +6,20 @@
*
*/

'use strict';

import Suite from '../jasmine/Suite';
import Suite, {Attributes} from '../jasmine/Suite';

describe('Suite', () => {
let suite;
let suite: Suite;

beforeEach(() => {
suite = new Suite({
getTestPath: () => '',
});
} as Attributes);
});

it("doesn't throw on addExpectationResult when there are no children", () => {
expect(() => {
// @ts-ignore
suite.addExpectationResult();
}).not.toThrow();
});
Expand Down
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

import expectationResultFactory from '../expectationResultFactory';

describe('expectationResultFactory', () => {
Expand Down
Expand Up @@ -3,15 +3,14 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';
export type SharedHookType = 'afterAll' | 'beforeAll';
export type HookType = SharedHookType | 'afterEach' | 'beforeEach';

describe.each([['beforeEach'], ['beforeAll'], ['afterEach'], ['afterAll']])(
'%s hooks error throwing',
fn => {
(fn: HookType) => {
test.each([
['String'],
[1],
Expand Down
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

describe('test/it error throwing', () => {
it(`it throws error with missing callback function`, () => {
expect(() => {
Expand All @@ -18,11 +16,13 @@ describe('test/it error throwing', () => {
});
it(`it throws an error when first argument isn't a string`, () => {
expect(() => {
// @ts-ignore
it(() => {});
}).toThrowError(`Invalid first argument, () => {}. It must be a string.`);
});
it('it throws an error when callback function is not a function', () => {
expect(() => {
// @ts-ignore
it('test3', 'test3b');
}).toThrowError(
'Invalid second argument, test3b. It must be a callback function.',
Expand All @@ -37,11 +37,13 @@ describe('test/it error throwing', () => {
});
test(`test throws an error when first argument isn't a string`, () => {
expect(() => {
// @ts-ignore
test(() => {});
}).toThrowError(`Invalid first argument, () => {}. It must be a string.`);
});
test('test throws an error when callback function is not a function', () => {
expect(() => {
// @ts-ignore
test('test6', 'test6b');
}).toThrowError(
'Invalid second argument, test6b. It must be a callback function.',
Expand Down
Expand Up @@ -6,6 +6,4 @@
*
*/

'use strict';

test('global.test', () => {});
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

describe('iterators', () => {
it('works for arrays', () => {
const mixedArray = [1, {}, []];
Expand Down Expand Up @@ -55,9 +53,14 @@ describe('iterators', () => {
});

it('works for Maps', () => {
const keyValuePairs = [['key1', 'value1'], ['key2', 'value2']];
const smallerKeyValuePairs = [['key1', 'value1']];
const biggerKeyValuePairs = [
const keyValuePairs: ReadonlyArray<[string, string]> = [
['key1', 'value1'],
['key2', 'value2'],
];
const smallerKeyValuePairs: ReadonlyArray<[string, string]> = [
['key1', 'value1'],
];
const biggerKeyValuePairs: ReadonlyArray<[string, string]> = [
['key1', 'value1'],
['key2', 'value2'],
['key3', 'value3'],
Expand Down
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

describe('matchers', () => {
it('proxies matchers to expect', () => {
expect(() => expect(1).toBe(2)).toThrowErrorMatchingSnapshot();
Expand Down
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

jest.useFakeTimers();

import pTimeout from '../pTimeout';
Expand Down
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

import queueRunner from '../queueRunner';

describe('queueRunner', () => {
Expand All @@ -28,6 +26,7 @@ describe('queueRunner', () => {
],
setTimeout,
};
// @ts-ignore
await queueRunner(options);
expect(fnOne).toHaveBeenCalled();
expect(fnTwo).toHaveBeenCalled();
Expand All @@ -51,6 +50,7 @@ describe('queueRunner', () => {
],
setTimeout,
};
// @ts-ignore
await queueRunner(options);
expect(fnOne).toHaveBeenCalled();
expect(fail).toHaveBeenCalled();
Expand Down Expand Up @@ -79,6 +79,7 @@ describe('queueRunner', () => {
],
setTimeout,
};
// @ts-ignore
await queueRunner(options);
expect(fnOne).toHaveBeenCalled();
expect(onException).toHaveBeenCalledWith(error);
Expand All @@ -87,7 +88,7 @@ describe('queueRunner', () => {
});

it('passes an error to `onException` on timeout.', async () => {
const fnOne = jest.fn(next => {});
const fnOne = jest.fn(_next => {});
const fnTwo = jest.fn(next => next());
const onException = jest.fn();
const options = {
Expand All @@ -106,6 +107,7 @@ describe('queueRunner', () => {
],
setTimeout,
};
// @ts-ignore
await queueRunner(options);
expect(fnOne).toHaveBeenCalled();
expect(onException).toHaveBeenCalled();
Expand All @@ -125,6 +127,7 @@ describe('queueRunner', () => {
queueableFns: [{fn: failFn}],
setTimeout,
};
// @ts-ignore
await queueRunner(options);

expect(options.fail).toHaveBeenCalledWith('miserably', 'failed');
Expand All @@ -149,6 +152,7 @@ describe('queueRunner', () => {
],
setTimeout,
};
// @ts-ignore
await queueRunner(options);
expect(fnOne).toHaveBeenCalled();
expect(fail).toHaveBeenCalledWith(error);
Expand Down
Expand Up @@ -6,29 +6,33 @@
*
*/

'use strict';

import JasmineReporter from '../reporter';
import {SuiteResult} from '../jasmine/Suite';
import {SpecResult} from '../jasmine/Spec';

describe('Jasmine2Reporter', () => {
let reporter;
let reporter: JasmineReporter;

beforeEach(() => {
// @ts-ignore
reporter = new JasmineReporter({});
});

it('reports nested suites', () => {
const makeSpec = name => ({
description: 'description',
failedExpectations: [],
fullName: name,
});
reporter.suiteStarted({description: 'parent'});
reporter.suiteStarted({description: 'child'});
const makeSpec = (name: string) =>
({
description: 'description',
failedExpectations: [],
fullName: name,
} as SpecResult);
reporter.suiteStarted({description: 'parent'} as SuiteResult);
reporter.suiteStarted({description: 'child'} as SuiteResult);
reporter.specDone(makeSpec('spec 1'));
// @ts-ignore
reporter.suiteDone();
reporter.suiteStarted({description: 'child 2'});
reporter.suiteStarted({description: 'child 2'} as SuiteResult);
reporter.specDone(makeSpec('spec 2'));
// @ts-ignore
reporter.jasmineDone();

return reporter.getResults().then(runResults => {
Expand Down
Expand Up @@ -6,11 +6,10 @@
*
*/

'use strict';

describe('test/it.todo error throwing', () => {
it('it throws error when given no arguments', () => {
expect(() => {
// @ts-ignore
it.todo();
}).toThrowError('Todo must be called with only a description.');
});
Expand All @@ -21,6 +20,7 @@ describe('test/it.todo error throwing', () => {
});
it('it throws error when given none string description', () => {
expect(() => {
// @ts-ignore
it.todo(() => {});
}).toThrowError('Todo must be called with only a description.');
});
Expand Down

0 comments on commit 7a4ee21

Please sign in to comment.