From 3904eb830313902464c6963b5f1100f252be4cee Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Tue, 4 Oct 2022 11:46:06 +0300 Subject: [PATCH] chore: lint files in `website/blog` directory (#13379) --- .eslintignore | 1 - .eslintrc.cjs | 19 +++++++++++++++++-- website/blog/2017-12-18-jest-22.md | 12 +++++++----- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.eslintignore b/.eslintignore index 36c1940c60f0..f27fa20f2296 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,7 +5,6 @@ bin/ packages/*/build/** packages/*/dist/** website/.docusaurus -website/blog website/build website/node_modules website/i18n/*.js diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 44f294b1affd..7ffcecadc90f 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -181,7 +181,6 @@ module.exports = { '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-namespace': 'off', '@typescript-eslint/no-empty-interface': 'off', - 'arrow-body-style': 'off', 'consistent-return': 'off', 'import/export': 'off', 'import/no-extraneous-dependencies': 'off', @@ -191,16 +190,32 @@ module.exports = { 'no-console': 'off', 'no-undef': 'off', 'no-unused-vars': 'off', - 'prettier/prettier': 'off', 'sort-keys': 'off', }, }, + // demonstration of matchers usage { files: ['**/UsingMatchers.md/**'], rules: { 'jest/prefer-to-be': 'off', }, }, + // demonstration of 'jest/valid-expect' rule + { + files: [ + '**/2017-05-06-jest-20-delightful-testing-multi-project-runner.md/**', + ], + rules: { + 'jest/valid-expect': 'off', + }, + }, + // Jest 11 did not had `toHaveLength` matcher + { + files: ['**/2016-04-12-jest-11.md/**'], + rules: { + 'jest/prefer-to-have-length': 'off', + }, + }, // snapshots in examples plus inline snapshots need to keep backtick { diff --git a/website/blog/2017-12-18-jest-22.md b/website/blog/2017-12-18-jest-22.md index 201d444f54fa..7d5ebb915953 100644 --- a/website/blog/2017-12-18-jest-22.md +++ b/website/blog/2017-12-18-jest-22.md @@ -25,7 +25,7 @@ To get a better understanding of custom runners and Jest as a platform, make sur In order to more easily identify which assertion is failing your test, we've added a code frame showing the context where the assertion is in order to focus on your own code. See the following example test: -``` +```js test('some test', () => { function someFunctionWhichShouldThrow() { if (false) { @@ -35,7 +35,7 @@ test('some test', () => { return 'success!'; } - expect(someFunctionWhichShouldThrow).toThrowError(); + expect(someFunctionWhichShouldThrow).toThrow(); }); ``` @@ -51,7 +51,7 @@ In Jest 22, we have added a codeframe, giving more context to the failing assert You can now use `toThrow` and `toThrowErrorMatchingSnapshot` on promise rejections in the same way you can on synchronous errors. -``` +```js async function throwingFunction() { throw new Error('This failed'); } @@ -81,17 +81,18 @@ Jest uses Babel under the hood to power code coverage and advanced mocking featu There has been a couple of changes to mock functions in Jest 22, making them even easier to use. Firstly, we added a [`mockName`](/docs/mock-function-api#mockfnmocknamevalue) property allowing you to name your mocks, which is useful in assertion failures. We have also made the Jest mock function serializable in `pretty-format`, meaning that you can snapshot test mocks. In Jest 21, `expect(jest.fn()).toMatchSnapshot()` would serialize to `[Function]`, in Jest 22, you might get something like this: -``` +```js test('my mocking test', () => { const mock = jest.fn().mockName('myMock'); - mock('hello', { foo: 'bar' }); + mock('hello', {foo: 'bar'}); expect(mock).toMatchSnapshot(); }); // Serializes to: +exports[`my mocking test 1`] = ` [MockFunction myMock] { "calls": Array [ Array [ @@ -102,6 +103,7 @@ test('my mocking test', () => { ], ], } +`; ``` ## Highlights from Jest 21