Skip to content

Commit

Permalink
fix: don't use jest.requireActual
Browse files Browse the repository at this point in the history
  • Loading branch information
mizdra committed Dec 28, 2021
1 parent 7683a9d commit 009081e
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions test/formatter/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
const mockFormatByFiles = jest.fn(() => 'formatByFiles');
const mockFormatByRules = jest.fn(() => 'formatByRules');

import { jest } from '@jest/globals';
import { ESLint } from 'eslint';
import { format } from '../../src/formatter/index.js';
import { fakeLintResult, fakeLintMessage } from '../test-util/eslint.js';

jest.mock('../../src/formatter/format-by-files', () => {
return {
...jest.requireActual('../../src/formatter/format-by-files'),
formatByFiles: mockFormatByFiles,
};
});
jest.mock('../../src/formatter/format-by-rules', () => {
return {
...jest.requireActual('../../src/formatter/format-by-rules'),
formatByRules: mockFormatByRules,
};
});

describe('format', () => {
test('call `formatByFiles` and `formatByRules`', () => {
const results: ESLint.LintResult[] = [
Expand All @@ -29,10 +12,13 @@ describe('format', () => {
const data: ESLint.LintResultData = { rulesMeta: {} };
const formattedText = format(results, data);
expect(formattedText).toMatchInlineSnapshot(`
"formatByFiles
formatByRules"
`);
expect(mockFormatByFiles).toBeCalledWith(results);
expect(mockFormatByRules).toBeCalledWith(results, data);
"- 1 file (0 file passed, 1 file failed) checked.

┌────────┬───────┬─────────┬────────────┬─────────────────┐
│ Rule │ Error │ Warning │ is fixable │ has suggestions │
├────────┼───────┼─────────┼────────────┼─────────────────┤
│ rule-a │ 1 │ 0 │ 0 │ 0 │
└────────┴───────┴─────────┴────────────┴─────────────────┘"
`);
});
});

0 comments on commit 009081e

Please sign in to comment.