Skip to content

Commit

Permalink
chore: update @ts-expect-error comments and tests (#10356)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Aug 2, 2020
1 parent 321838f commit 9625826
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 40 deletions.
6 changes: 3 additions & 3 deletions packages/jest-cli/src/__tests__/cli/args.test.ts
Expand Up @@ -101,12 +101,12 @@ describe('check', () => {

describe('buildArgv', () => {
it('should return only camelcased args ', () => {
// @ts-expect-error
const mockProcessArgv = jest
// @ts-expect-error
.spyOn(process.argv, 'slice')
.mockImplementation(() => ['--clear-mocks']);
// @ts-expect-error
const actual = buildArgv(null);

const actual = buildArgv();
expect(actual).not.toHaveProperty('clear-mocks');
expect(actual).toHaveProperty('clearMocks', true);
mockProcessArgv.mockRestore();
Expand Down
3 changes: 0 additions & 3 deletions packages/jest-config/src/__tests__/getMaxWorkers.test.ts
Expand Up @@ -39,19 +39,16 @@ describe('getMaxWorkers', () => {
describe('% based', () => {
it('50% = 2 workers', () => {
const argv = {maxWorkers: '50%'};
// @ts-expect-error: need to fix the typing
expect(getMaxWorkers(argv)).toBe(2);
});

it('< 0 workers should become 1', () => {
const argv = {maxWorkers: '1%'};
// @ts-expect-error: need to fix the typing
expect(getMaxWorkers(argv)).toBe(1);
});

it("0% shouldn't break", () => {
const argv = {maxWorkers: '0%'};
// @ts-expect-error: need to fix the typing
expect(getMaxWorkers(argv)).toBe(1);
});
});
Expand Down
2 changes: 0 additions & 2 deletions packages/jest-config/src/__tests__/readConfigs.test.ts
Expand Up @@ -29,7 +29,6 @@ test('readConfigs() loads async config file', async () => {
rootDir: './',
}));
await expect(
// @ts-expect-error
readConfigs(
<Config.Argv>{} /* argv */,
['./some-jest-config-file.js'] /* projectPaths */,
Expand All @@ -43,7 +42,6 @@ test('readConfigs() reject if async was rejected', async () => {
throw new Error('Some error');
});
await expect(
// @ts-expect-error
readConfigs(
<Config.Argv>{} /* argv */,
['./some-jest-config-file.js'] /* projectPaths */,
Expand Down
31 changes: 11 additions & 20 deletions packages/jest-matcher-utils/src/__tests__/index.test.ts
Expand Up @@ -103,44 +103,39 @@ describe('stringify()', () => {
});

describe('ensureNumbers()', () => {
const matcherName = 'toBeCloseTo';

test('dont throw error when variables are numbers', () => {
expect(() => {
// @ts-expect-error
ensureNumbers(1, 2);
ensureNumbers(1, 2, matcherName);
}).not.toThrow();
if (isBigIntDefined) {
expect(() => {
// @ts-expect-error
ensureNumbers(BigInt(1), BigInt(2));
ensureNumbers(BigInt(1), BigInt(2), matcherName);
}).not.toThrow();
}
});

test('throws error when expected is not a number (backward compatibility)', () => {
expect(() => {
// @ts-expect-error
ensureNumbers(1, 'not_a_number', '.toBeCloseTo');
ensureNumbers(1, 'not_a_number', `.${matcherName}`);
}).toThrowErrorMatchingSnapshot();
});

test('throws error when received is not a number (backward compatibility)', () => {
expect(() => {
// @ts-expect-error
ensureNumbers('not_a_number', 3, '.toBeCloseTo');
ensureNumbers('not_a_number', 3, `.${matcherName}`);
}).toThrowErrorMatchingSnapshot();
});

describe('with options', () => {
const matcherName = 'toBeCloseTo';

test('promise empty isNot false received', () => {
const options: MatcherHintOptions = {
isNot: false,
promise: '',
secondArgument: 'precision',
};
expect(() => {
// @ts-expect-error
ensureNumbers('', 0, matcherName, options);
}).toThrowErrorMatchingSnapshot();
});
Expand All @@ -151,7 +146,6 @@ describe('ensureNumbers()', () => {
// promise undefined is equivalent to empty string
};
expect(() => {
// @ts-expect-error
ensureNumbers(0.1, undefined, matcherName, options);
}).toThrowErrorMatchingSnapshot();
});
Expand All @@ -162,7 +156,6 @@ describe('ensureNumbers()', () => {
promise: 'rejects',
};
expect(() => {
// @ts-expect-error
ensureNumbers(0.01, '0', matcherName, options);
}).toThrowErrorMatchingSnapshot();
});
Expand All @@ -173,7 +166,6 @@ describe('ensureNumbers()', () => {
promise: 'rejects',
};
expect(() => {
// @ts-expect-error
ensureNumbers(Symbol('0.1'), 0, matcherName, options);
}).toThrowErrorMatchingSnapshot();
});
Expand All @@ -184,7 +176,6 @@ describe('ensureNumbers()', () => {
promise: 'resolves',
};
expect(() => {
// @ts-expect-error
ensureNumbers(false, 0, matcherName, options);
}).toThrowErrorMatchingSnapshot();
});
Expand All @@ -195,30 +186,30 @@ describe('ensureNumbers()', () => {
promise: 'resolves',
};
expect(() => {
// @ts-expect-error
ensureNumbers(0.1, null, matcherName, options);
}).toThrowErrorMatchingSnapshot();
});
});
});

describe('ensureNoExpected()', () => {
const matcherName = 'toBeDefined';

test('dont throw error when undefined', () => {
expect(() => {
// @ts-expect-error
ensureNoExpected(undefined);
ensureNoExpected(undefined, matcherName);
}).not.toThrow();
});

test('throws error when expected is not undefined with matcherName', () => {
expect(() => {
ensureNoExpected({a: 1}, '.toBeDefined');
ensureNoExpected({a: 1}, `.${matcherName}`);
}).toThrowErrorMatchingSnapshot();
});

test('throws error when expected is not undefined with matcherName and options', () => {
expect(() => {
ensureNoExpected({a: 1}, 'toBeDefined', {isNot: true});
ensureNoExpected({a: 1}, matcherName, {isNot: true});
}).toThrowErrorMatchingSnapshot();
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-serializer/src/__tests__/index.test.ts
Expand Up @@ -19,8 +19,8 @@ const objs = [
{key1: 'foo', key2: 'bar', key3: {array: [null, {}]}},
{minusInf: -Infinity, nan: NaN, plusInf: +Infinity},
{date: new Date(1234567890), re: /foo/gi},
// @ts-expect-error - testing NaN
{
// @ts-expect-error - testing NaN
map: new Map([
[NaN, 4],
[undefined, 'm'],
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-source-map/src/__tests__/getCallsite.test.ts
Expand Up @@ -44,7 +44,7 @@ describe('getCallsite', () => {

const sourceMapColumn = 1;
const sourceMapLine = 2;
// @ts-expect-error

SourceMap.SourceMapConsumer = class {
originalPositionFor(params: Record<string, any>) {
expect(params).toMatchObject({
Expand Down
Expand Up @@ -27,7 +27,7 @@ describe('formatTestResults', () => {
};

it('includes test full name', () => {
const result = formatTestResults(results, null, null);
const result = formatTestResults(results, undefined, null);
expect(result.testResults[0].assertionResults[0].fullName).toEqual(
assertion.fullName,
);
Expand Down
1 change: 0 additions & 1 deletion packages/pretty-format/src/__tests__/prettyFormat.test.ts
Expand Up @@ -540,7 +540,6 @@ describe('prettyFormat()', () => {

it('throws on invalid options', () => {
expect(() => {
// @ts-expect-error
prettyFormat({}, {invalidOption: true});
}).toThrow();
});
Expand Down
10 changes: 2 additions & 8 deletions packages/pretty-format/src/__tests__/react.test.tsx
Expand Up @@ -635,10 +635,7 @@ test('throws if theme option is null', () => {
);
expect(() => {
// @ts-expect-error
formatElement(jsx, {
highlight: true,
theme: null,
});
formatElement(jsx, {highlight: true, theme: null});
}).toThrow('pretty-format: Option "theme" must not be null.');
});

Expand All @@ -650,10 +647,7 @@ test('throws if theme option is not of type "object"', () => {
'Hello, Mouse!',
);
// @ts-expect-error
formatElement(jsx, {
highlight: true,
theme: 'beautiful',
});
formatElement(jsx, {highlight: true, theme: 'beautiful'});
}).toThrow(
'pretty-format: Option "theme" must be of type "object" but instead received "string".',
);
Expand Down

0 comments on commit 9625826

Please sign in to comment.