{"id":2363,"date":"2022-01-26T13:07:18","date_gmt":"2022-01-26T13:07:18","guid":{"rendered":"https:\/\/lvboard.infostore.in.ua\/?p=2363"},"modified":"2022-01-26T13:07:18","modified_gmt":"2022-01-26T13:07:18","slug":"%d1%88%d0%bf%d0%b0%d1%80%d0%b3%d0%b0%d0%bb%d0%ba%d0%b0-%d0%bf%d0%be-jest-%d1%81-%d0%bf%d1%80%d0%b8%d0%bc%d0%b5%d1%80%d0%b0%d0%bc%d0%b8-%d0%ba%d0%be%d0%b4%d0%b0","status":"publish","type":"post","link":"https:\/\/lvboard.infostore.in.ua\/?p=2363","title":{"rendered":"\u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e Jest \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0434\u0430"},"content":{"rendered":"\n<p>\u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e Jest (Stylesheet Jest)<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2><a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/cheatsheets-bestpractices.md#%D0%B1%D0%B0%D0%B7%D0%BE%D0%B2%D0%B0%D1%8F-%D1%81%D1%82%D1%80%D1%83%D0%BA%D1%82%D1%83%D1%80%D0%B0-%D1%82%D0%B5%D1%81%D1%82%D0%B0\"><\/a>\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0442\u0435\u0441\u0442\u0430<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">describe('\u0412\u044b\u0431\u043e\u0440 \u0446\u0432\u0435\u0442\u0430', () =&gt; {\n  beforeAll(() =&gt; {\n    \/* \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u0432\u0441\u0435\u043c\u0438 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 *\/\n  })\n  afterAll(() =&gt; {\n    \/* \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0445 \u0442\u0435\u0441\u0442\u043e\u0432 *\/\n  })\n  beforeEach(() =&gt; {\n    \/* \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u043a\u0430\u0436\u0434\u044b\u043c \u0442\u0435\u0441\u0442\u043e\u043c *\/\n  })\n  afterEach(() =&gt; {\n    \/* \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 *\/\n  })\n\n  test('\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0446\u0432\u0435\u0442', () =&gt; {\n    const actual = fn(['Alice', 'Bob', 'John'])\n    expect(actual).toEqual(['Pink Alice', 'Pink Bob', 'Pink John'])\n  })\n})<\/pre>\n\n\n\n<h2><a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/cheatsheets-bestpractices.md#%D0%BF%D0%BE%D0%B8%D1%81%D0%BA-%D1%81%D0%BE%D0%B2%D0%BF%D0%B0%D0%B4%D0%B5%D0%BD%D0%B8%D0%B9\"><\/a>\u041f\u043e\u0438\u0441\u043a \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439<\/h2>\n\n\n\n<p><a href=\"http:\/\/jestjs.io\/docs\/en\/using-matchers\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0438\u0441\u043a\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439<\/a>,&nbsp;<a href=\"https:\/\/facebook.github.io\/jest\/docs\/expect.html\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f<\/a><\/p>\n\n\n\n<h3><a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/cheatsheets-bestpractices.md#%D0%B1%D0%B0%D0%B7%D0%BE%D0%B2%D1%8B%D0%B9-%D0%BF%D0%BE%D0%B8%D1%81%D0%BA-%D1%81%D0%BE%D0%B2%D0%BF%D0%B0%D0%B4%D0%B5%D0%BD%D0%B8%D0%B9\"><\/a>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">expect(42).toBe(42) \/\/ \u0421\u0442\u0440\u043e\u0433\u043e\u0435 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e (===)\nexpect(42).not.toBe(3) \/\/ \u0421\u0442\u0440\u043e\u0433\u043e\u0435 \u043d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e (!==)\nexpect([1, 2]).toEqual([1, 2]) \/\/ \u0413\u043b\u0443\u0431\u043e\u043a\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435\nexpect({ a: undefined, b: 2 }).toEqual({ b: 2 }) \/\/ \u0413\u043b\u0443\u0431\u043e\u043a\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435\nexpect({ a: undefined, b: 2 }).not.toStrictEqual({ b: 2 }) \/\/ \u0421\u0442\u0440\u043e\u0433\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435<\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/cheatsheets-bestpractices.md#%D0%BE%D0%BF%D1%80%D0%B5%D0%B4%D0%B5%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5-%D0%B8%D1%81%D1%82%D0%B8%D0%BD%D0%BD%D0%BE%D1%81%D1%82%D0%B8\"><\/a>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0441\u0442\u0438<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ \u0421\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438\nexpect('foo').toBeTruthy()\n\/\/ \u0421\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438\nexpect('').toBeFalsy()\n\/\/ \u0421\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 `null`\nexpect(null).toBeNull()\n\/\/ \u0421\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 `undefined`\nexpect(undefined).toBeUndefined()\n\/\/ \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e\nexpect(7).toBeDefined()\n\/\/ \u0421\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 `true` \u0438\u043b\u0438 `false`\nexpect(true).toEqual(expect.any(Boolean))<\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/cheatsheets-bestpractices.md#%D1%87%D0%B8%D1%81%D0%BB%D0%B0\"><\/a>\u0427\u0438\u0441\u043b\u0430<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">expect(2).toBeGreaterThan(1)\nexpect(1).toBeGreaterThanOrEqual(1)\nexpect(1).toBeLessThan(2)\nexpect(1).toBeLessThanOrEqual(1)\nexpect(0.2 + 0.1).toBeCloseTo(0.3, 5)\nexpect(NaN).toEqual(expect.any(Number))<\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/cheatsheets-bestpractices.md#%D1%81%D1%82%D1%80%D0%BE%D0%BA%D0%B8\"><\/a>\u0421\u0442\u0440\u043e\u043a\u0438<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">expect('\u0434\u043b\u0438\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430').toMatch('\u0441\u0442\u0440')\nexpect('\u0441\u0442\u0440\u043e\u043a\u0430').toEqual(expect.any(String))\nexpect('\u043a\u043e\u0444\u0435').toMatch(\/\u0444\/)\nexpect('\u043f\u0438\u0446\u0446\u0430').not.toMatch('\u043a\u043e\u0444\u0435')\nexpect(['\u043f\u0438\u0446\u0446\u0430', '\u043a\u043e\u0444\u0435']).toEqual([expect.stringContaining('\u0446\u0446'), expect.stringMatching(\/\u0444\/)])<\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/cheatsheets-bestpractices.md#%D0%BC%D0%B0%D1%81%D1%81%D0%B8%D0%B2%D1%8B\"><\/a>\u041c\u0430\u0441\u0441\u0438\u0432\u044b<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">expect([]).toEqual(expect.any(Array))\nexpect(['Alice', 'Bob', 'John']).toHaveLength(3)\nexpect(['Alice', 'Bob', 'John']).toContain('Alice')\nexpect([{ a: 1 }, { a: 2 }]).toContainEqual({ a: 1 })\nexpect(['Alice', 'Bob', 'John']).toEqual(expect.arrayContaining(['Alice', 'Bob']))<\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/cheatsheets-bestpractices.md#%D0%BE%D0%B1%D1%8A%D0%B5%D0%BA%D1%82%D1%8B\"><\/a>\u041e\u0431\u044a\u0435\u043a\u0442\u044b<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">expect({ a: 1 }).toHaveProperty('a')\nexpect({ a: 1 }).toHaveProperty('a', 1)\nexpect({ a: { b: 1 } }).toHaveProperty('a.b')\nexpect({ a: 1, b: 2 }).toMatchObject({ a: 1 })\nexpect({ a: 1, b: 2 }).toMatchObject({\n  a: expect.any(Number),\n  b: expect.any(Number)\n})\nexpect([{ a: 1 }, { b: 2 }]).toEqual([\n  expect.objectContaining({ a: expect.any(Number) }),\n  expect.anything()\n])<\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/cheatsheets-bestpractices.md#%D0%B8%D1%81%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D1%8F\"><\/a>\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ const fn = () =&gt; { throw new Error('\u0423\u043f\u0441!') }\nexpect(fn).toThrow()\nexpect(fn).toThrow('\u0423\u043f\u0441')\nexpect(fn).toThrowErrorMatchingSnapshot()<\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/cheatsheets-bestpractices.md#%D1%81%D0%BD%D0%B8%D0%BC%D0%BA%D0%B8\"><\/a>\u0421\u043d\u0438\u043c\u043a\u0438<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">expect(node).toMatchSnapshot()\nexpect(user).toMatchSnapshot({\n  date: expect.any(Date)\n})\nexpect(user).toMatchInlineSnapshot()<\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/cheatsheets-bestpractices.md#%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F-%D0%B4%D0%BB%D1%8F-%D1%81%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D1%8F-%D0%BC%D0%BE%D0%BA%D0%BE%D0%B2-%D1%84%D0%B8%D0%BA%D1%86%D0%B8%D0%B9\"><\/a>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u00ab\u043c\u043e\u043a\u043e\u0432\u00bb (\u0444\u0438\u043a\u0446\u0438\u0439)<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ const fn = jest.fn()\n\/\/ const fn = jest.fn().mockName('\u0415\u0434\u0438\u043d\u043e\u0440\u043e\u0433') - \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0444\u0438\u043a\u0446\u0438\u044f\nexpect(fn).toBeCalled() \/\/ \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430\nexpect(fn).not.toBeCalled() \/\/ \u0424\u0443\u043d\u043a\u0446\u0438\u044f *\u043d\u0435 \u0431\u044b\u043b\u0430* \u0432\u044b\u0437\u0432\u0430\u043d\u0430\nexpect(fn).toHaveBeenCalledTimes(1) \/\/ \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u043e\u0434\u0438\u043d \u0440\u0430\u0437\nexpect(fn).toBeCalledWith(arg1, arg2) \/\/ \u041b\u044e\u0431\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u043b\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438\nexpect(fn).toHaveBeenLastCalledWith(arg1, arg2) \/\/ \u041f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0435\u0439 \u0431\u044b\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b\nexpect(fn).toHaveBeenNthCalledWith(args) \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u043b\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438\nexpect(fn).toHaveReturnedTimes(2) \/\/ \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u043e\u0448\u0438\u0431\u043e\u043a\nexpect(fn).toHaveReturnedWith(value) \/\/ \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\nexpect(fn).toHaveLastReturnedWith(value) \/\/ \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0435\u0440\u043d\u0443\u043b \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\nexpect(fn).toHaveNthReturnedWith(value) \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0435\u0440\u043d\u0443\u043b \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\nexpect(fn.mock.calls).toEqual([['first', 'call', 'args'], ['second', 'call', 'args']]) \/\/ \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u0432\nexpect(fn.mock.calls[0][0]).toBe(2) \/\/ fn.mock.calls[0][0] \u2014 \u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430<\/pre>\n\n\n\n<p>\u00ab\u0410\u043b\u0438\u0430\u0441\u044b\u00bb (\u0441\u0438\u043d\u043e\u043d\u0438\u043c\u044b)<\/p>\n\n\n\n<ul><li><code>toBeCalled<\/code>&nbsp;\u2192&nbsp;<code>toHaveBeenCalled<\/code><\/li><li><code>toBeCalledWith<\/code>&nbsp;\u2192&nbsp;<code>toHaveBeenCalledWith<\/code><\/li><li><code>lastCalledWith<\/code>&nbsp;\u2192&nbsp;<code>toHaveBeenLastCalledWith<\/code><\/li><li><code>nthCalledWith<\/code>&nbsp;\u2192&nbsp;<code>toHaveBeenNthCalledWith<\/code><\/li><li><code>toReturnTimes<\/code>&nbsp;\u2192&nbsp;<code>toHaveReturnedTimes<\/code><\/li><li><code>toReturnWith<\/code>&nbsp;\u2192&nbsp;<code>toHaveReturnedWith<\/code><\/li><li><code>lastReturnedWith<\/code>&nbsp;\u2192&nbsp;<code>toHaveLastReturnedWith<\/code><\/li><li><code>nthReturnedWith<\/code>&nbsp;\u2192&nbsp;<code>toHaveNthReturnedWith<\/code><\/li><\/ul>\n\n\n\n<h3>\u041f\u0440\u0438\u043c\u0435\u0441\u0438<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">expect(new A()).toBeInstanceOf(A)\nexpect(() =&gt; {}).toEqual(expect.any(Function))\nexpect('\u043f\u0438\u0446\u0446\u0430').toEqual(expect.anything())<\/pre>\n\n\n\n<h3>\u041f\u043e\u0438\u0441\u043a \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439 \u0441 \u043f\u0440\u043e\u043c\u0438\u0441\u0430\u043c\u0438<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">test('\u0420\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \"\u043b\u0438\u043c\u043e\u043d\"', () =&gt; {\n  expect.assertions(1)\n  \/\/ \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 `return`\n  return expect(Promise.resolve('\u043b\u0438\u043c\u043e\u043d')).resolves.toBe('\u043b\u0438\u043c\u043e\u043d')\n  return expect(Promise.reject('\u043e\u0441\u044c\u043c\u0438\u043d\u043e\u0433')).rejects.toBeDefined()\n  return expect(Promise.reject(Error('\u043f\u0438\u0446\u0446\u0430'))).rejects.toThrow()\n})<\/pre>\n\n\n\n<p>\u0418\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e&nbsp;<code>async\/await<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">test('\u0420\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \"\u043b\u0438\u043c\u043e\u043d\"', async () =&gt; {\n  expect.assertions(2)\n  await expect(Promise.resolve('\u043b\u0438\u043c\u043e\u043d')).resolves.toBe('\u043b\u0438\u043c\u043e\u043d')\n  await expect(Promise.resolve('\u043b\u0438\u043c\u043e\u043d')).resolves.not.toBe('\u043e\u0441\u044c\u043c\u0438\u043d\u043e\u0433')\n})<\/pre>\n\n\n\n<p><a href=\"https:\/\/facebook.github.io\/jest\/docs\/en\/expect.html#resolves\">\u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f<\/a><\/p>\n\n\n\n<h2>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b<\/h2>\n\n\n\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435&nbsp;<a href=\"https:\/\/facebook.github.io\/jest\/docs\/en\/tutorial-async.html\">\u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432<\/a>&nbsp;\u0432 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Jest.<\/p>\n\n\n\n<p>\u0425\u043e\u0440\u043e\u0448\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0439 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0445 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0439 (assertions) \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u0430\u0445, \u0442\u0435\u0441\u0442 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u044b.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">test('\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0442\u0435\u0441\u0442', () =&gt; {\n  expect.assertions(3) \/\/ \u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u0442\u0440\u0438 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f\n  \/\/ \u0438\u043b\u0438\n  expect.hasAssertions() \/\/ \u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u043e\u0434\u043d\u043e \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435\n\n  \/\/ \u0414\u0430\u043b\u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b\n})<\/pre>\n\n\n\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u0444\u0430\u0439\u043b\u0435, \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u043b\u044e\u0431\u044b\u0445&nbsp;<code>describe<\/code>&nbsp;\u0438&nbsp;<code>test<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">beforeEach(expect.hasAssertions)<\/pre>\n\n\n\n<p>\u042d\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043a\u043e\u0433\u0434\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0439 \u2014&nbsp;<code>expect.assertions(3)<\/code>.<\/p>\n\n\n\n<h3>async\/await<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">test('\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0442\u0435\u0441\u0442', async () =&gt; {\n  expect.assertions(1)\n  const result = await runAsyncOperation()\n  expect(result).toBe(true)\n})<\/pre>\n\n\n\n<h3>\u041f\u0440\u043e\u043c\u0438\u0441\u044b<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">test('\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0442\u0435\u0441\u0442', () =&gt; {\n  expect.assertions(1)\n  return runAsyncOperation().then(result =&gt; {\n    expect(result).toBe(true)\n  })\n})<\/pre>\n\n\n\n<h3>\u041a\u043e\u043b\u043b\u0431\u0435\u043a&nbsp;<code>done()<\/code><\/h3>\n\n\n\n<p>\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u043e \u0432 \u0431\u043b\u043e\u043a&nbsp;<code>try\/catch<\/code>, \u0438\u043d\u0430\u0447\u0435 Jest \u0431\u0443\u0434\u0435\u0442 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">test('\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0442\u0435\u0441\u0442', done =&gt; {\n  expect.assertions(1)\n  runAsyncOperation()\n  setTimeout(() =&gt; {\n    try {\n      const result = getAsyncOperationResult()\n      expect(result).toBe(true)\n      done()\n    } catch (err) {\n      done.fail(err)\n    }\n  })\n})<\/pre>\n\n\n\n<h2>\u0424\u0438\u043a\u0446\u0438\u0438<\/h2>\n\n\n\n<h3>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0444\u0438\u043a\u0446\u0438\u0439<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">test('\u0412\u044b\u0437\u043e\u0432 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0430', () =&gt; {\n  const callback = jest.fn()\n  fn(callback)\n  expect(callback).toBeCalled()\n  expect(callback.mock.calls[0][1].baz).toBe('\u043f\u0438\u0446\u0446\u0430') \/\/ \u0412\u0442\u043e\u0440\u043e\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430\n  \/\/ \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u043d\u043e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0439\n  expect(callback).toHaveBeenLastCalledWith('\u043c\u044f\u0441\u043e', expect.anything(), '\u043c\u0430\u0440\u0433\u0430\u0440\u0438\u0442\u0430');\n})<\/pre>\n\n\n\n<p>\u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043d\u0438\u043c\u043a\u0438:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">test('\u0412\u044b\u0437\u043e\u0432 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0430', () =&gt; {\n  const callback = jest.fn().mockName('\u0415\u0434\u0438\u043d\u043e\u0440\u043e\u0433')\n  fn(callback)\n  expect(callback).toMatchSnapshot()\n  \/\/ -&gt;\n  \/\/ [MockFunction \u0415\u0434\u0438\u043d\u043e\u0440\u043e\u0433] {\n  \/\/   \"calls\": Array [\n  \/\/ ...\n})<\/pre>\n\n\n\n<p>\u0418 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e&nbsp;<code>jest.fn()<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const callback = jest.fn(() =&gt; true)<\/pre>\n\n\n\n<p><a href=\"https:\/\/facebook.github.io\/jest\/docs\/mock-function-api.html\">\u0427\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/a><\/p>\n\n\n\n<h3>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435, \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/h3>\n\n\n\n<p>\u0412\u0430\u0448\u0438 \u0444\u0438\u043a\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const callback = jest.fn().mockReturnValue(true);\nconst callbackOnce = jest.fn().mockReturnValueOnce(true);<\/pre>\n\n\n\n<p>\u0418\u043b\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<ins>https:\/\/googleads.g.doubleclick.net\/pagead\/ads?client=ca-pub-5265008544060842&amp;output=html&amp;h=174&amp;slotname=6021157728&amp;adk=1238341641&amp;adf=1504049979&amp;pi=t.ma~as.6021157728&amp;w=696&amp;fwrn=4&amp;lmt=1612760223&amp;rafmt=11&amp;psa=1&amp;format=696&#215;174&amp;url=https%3A%2F%2Fbookflow.ru%2Fshpargalka-po-jest-s-primerami-koda%2F&amp;flash=0&amp;host=ca-host-pub-2644536267352236&amp;wgl=1&amp;dt=1643202359645&amp;bpp=5&amp;bdt=763&amp;idt=338&amp;shv=r20220120&amp;mjsv=m202201240101&amp;ptt=9&amp;saldr=aa&amp;abxe=1&amp;cookie=ID%3D53d09eedf053366f-22c28a372bcd0013%3AT%3D1643201667%3ART%3D1643201667%3AS%3DALNI_Mb1ucFagtDc-cmhxjeor_SzpI1WJQ&amp;prev_fmts=0x0&amp;nras=1&amp;correlator=7763405730272&amp;frm=20&amp;pv=1&amp;ga_vid=322347871.1643202360&amp;ga_sid=1643202360&amp;ga_hid=525367307&amp;ga_fc=0&amp;rplot=4&amp;u_tz=120&amp;u_his=2&amp;u_h=768&amp;u_w=1366&amp;u_ah=728&amp;u_aw=1366&amp;u_cd=24&amp;u_sd=1&amp;adx=141&amp;ady=7822&amp;biw=1349&amp;bih=615&amp;scr_x=0&amp;scr_y=0&amp;eid=44750774%2C44753738%2C31064037%2C31064528&amp;oid=2&amp;pvsid=2817133588523098&amp;pem=199&amp;tmod=1215786858&amp;nvt=1&amp;ref=https%3A%2F%2Fbookflow.ru%2Fshpargalka-po-create-react-app%2F&amp;eae=0&amp;fc=1920&amp;brdim=-8%2C-8%2C-8%2C-8%2C1366%2C0%2C1382%2C744%2C1366%2C615&amp;vis=1&amp;rsz=%7C%7CoeEbr%7C&amp;abl=CS&amp;pfx=0&amp;fu=128&amp;bc=31&amp;ifi=2&amp;uci=a!2&amp;btvi=1&amp;fsb=1&amp;xpc=MEdTFhXkGD&amp;p=https%3A\/\/bookflow.ru&amp;dtd=414<\/ins><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const promise = jest.fn().mockResolvedValue(true);\nconst promiseOnce = jest.fn().mockResolvedValueOnce(true);<\/pre>\n\n\n\n<p>\u041e\u043d\u0438 \u0434\u0430\u0436\u0435 \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u043a\u043b\u043e\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const failedPromise = jest.fn().mockRejectedValue(\"\u0420\u043e\u0441\u043a\u043e\u0441\u043c\u043e\u0441, \u0443 \u043d\u0430\u0441 \u0441\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043e\u043a\u0430\u0437\u0438\u044f\");\nconst failedPromiseOnce = jest.fn().mockRejectedValueOnce(\"\u0420\u043e\u0441\u043a\u043e\u0441\u043c\u043e\u0441, \u0443 \u043d\u0430\u0441 \u0441\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043e\u043a\u0430\u0437\u0438\u044f\");<\/pre>\n\n\n\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const callback = jest.fn()\n  .mockReturnValueOnce(false)\n  .mockReturnValue(true);\n\n\/\/ -&gt;\n\/\/  \u0432\u044b\u0437\u043e\u0432 1: false\n\/\/  \u0432\u044b\u0437\u043e\u0432 2+: true<\/pre>\n\n\n\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0438\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430&nbsp;<code>jest.mock()<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">jest.mock('lodash\/memoize', () =&gt; a =&gt; a) \/\/ \u0414\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f lodash\/memoize\njest.mock('lodash\/memoize', () =&gt; a =&gt; a, { virtual: true }) \/\/ \u0420\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f lodash\/memoize \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c<\/pre>\n\n\n\n<p><a href=\"https:\/\/facebook.github.io\/jest\/docs\/jest-object.html#jestmockmodulename-factory-options\">\u0427\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/a><\/p>\n\n\n\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438&nbsp;<code>babel-jest<\/code>&nbsp;\u0432\u044b\u0437\u043e\u0432\u044b&nbsp;<code>jest.mock()<\/code>&nbsp;\u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0431\u043b\u043e\u043a\u0430 \u043a\u043e\u0434\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435&nbsp;<code>jest.doMock()<\/code>&nbsp;\u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f.<\/p>\n\n\n\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0438\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u0430\u0445<\/h3>\n\n\n\n<ol><li>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440,&nbsp;<code>__mocks__\/lodash\/memoize.js<\/code>:module.exports = a =&gt; a<\/li><li>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043c \u0435\u0433\u043e \u0432 \u0442\u0435\u0441\u0442:jest.mock(&#8216;lodash\/memoize&#8217;)<\/li><\/ol>\n\n\n\n<p><a href=\"https:\/\/facebook.github.io\/jest\/docs\/manual-mocks.html\">\u0427\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/a><\/p>\n\n\n\n<h3>\u041c\u0435\u0442\u043e\u0434\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0444\u0438\u043a\u0446\u0438\u0439<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">const spy = jest.spyOn(console, 'log').mockImplementation(() =&gt; {})\nexpect(console.log.mock.calls).toEqual([['dope'], ['nope']])\nspy.mockRestore()<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">const spy = jest.spyOn(ajax, 'request').mockImplementation(() =&gt; Promise.resolve({ success: true }))\nexpect(spy).toHaveBeenCalled()\nspy.mockRestore()<\/pre>\n\n\n\n<h3>\u0413\u0435\u0442\u0442\u0435\u0440\u044b \u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u044b \u0444\u0438\u043a\u0446\u0438\u0439<\/h3>\n\n\n\n<p>\u041d\u043e\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const location = {}\nconst getTitle = jest.spyOn(location, 'title', 'get').mockImplementation(() =&gt; '\u043f\u0438\u0446\u0446\u0430')\nconst setTitle = jest.spyOn(location, 'title', 'set').mockImplementation(() =&gt; {})<\/pre>\n\n\n\n<p>\u0421\u0442\u0430\u0440\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const getTitle = jest.fn(() =&gt; '\u043f\u0438\u0446\u0446\u0430')\nconst setTitle = jest.fn()\nconst location = {}\nObject.defineProperty(location, 'title', {\n  get: getTitle,\n  set: setTitle\n})<\/pre>\n\n\n\n<h3>\u041e\u0447\u0438\u0441\u0442\u043a\u0430 \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0438\u043a\u0446\u0438\u0439<\/h3>\n\n\n\n<p>\u0414\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u0444\u0438\u043a\u0446\u0438\u0438:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">fn.mockClear() \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u0434\u0430\u0442\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0438\u043a\u0446\u0438\u0438 (fn.mock.calls, fn.mock.instances)\nfn.mockReset() \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u043b\u044e\u0431\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0438\u043a\u0446\u0438\u0438\nfn.mockRestore() \/\/ \u0421\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e<\/pre>\n\n\n\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435:&nbsp;<code>mockRestore()<\/code>&nbsp;\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u0444\u0438\u043a\u0446\u0438\u044f\u043c, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e&nbsp;<code>jest.spyOn()<\/code>.<\/p>\n\n\n\n<p>\u0414\u043b\u044f \u0432\u0441\u0435\u0445 \u0444\u0438\u043a\u0446\u0438\u0439:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">jest.clearAllMocks()\njest.resetAllMocks()\njest.restoreAllMocks()<\/pre>\n\n\n\n<h3>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u043c\u043e\u0434\u0443\u043b\u044e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u00ab\u043c\u043e\u043a\u043e\u0432\u00bb<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">jest.mock('fs')\nconst fs = require('fs') \/\/ \u041c\u043e\u0434\u0443\u043b\u044c \u0441 \"\u043c\u043e\u043a\u043e\u043c\"\nconst fs = require.requireActual('fs') \/\/ \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c<\/pre>\n\n\n\n<h3>\u0424\u0438\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u044b<\/h3>\n\n\n\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u043a\u043e\u0434\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u044b (<code>setTimeout<\/code>,&nbsp;<code>setInterval<\/code>,&nbsp;<code>clearTimeout<\/code>,&nbsp;<code>clearInterval<\/code>).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ \u0420\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0438\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432\njest.useFakeTimers()\n\ntest('\u0423\u0431\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f', () =&gt; {\n  const callback = jest.fn()\n\n  \/\/ \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043a\u043e\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f `setTimeout()` \u0438\u043b\u0438 `setInterval()`\n  const actual = someFunctionThatUseTimers(callback)\n\n  \/\/ \u041f\u0435\u0440\u0435\u043c\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0434\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432\n  jest.runAllTimers()\n\n  \/\/ \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b\n  expect(callback).toHaveBeenCalledTimes(1)\n})<\/pre>\n\n\n\n<p>\u0418\u043b\u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0442\u0430\u0439\u043c\u0435\u0440\u044b \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e&nbsp;<a href=\"https:\/\/jestjs.io\/docs\/en\/timer-mocks#advance-timers-by-time\">advanceTimersByTime()<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ \u0420\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0438\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432\njest.useFakeTimers()\n\ntest('\u0423\u0431\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f', () =&gt; {\n  const callback = jest.fn()\n\n  \/\/  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043a\u043e\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f `setTimeout()` \u0438\u043b\u0438 `setInterval()`\n  const actual = someFunctionThatUseTimers(callback)\n\n  \/\/ \u041f\u0435\u0440\u0435\u043c\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043d\u0430 250 \u043c\u0441\n  jest.advanceTimersByTime(250)\n\n  \/\/ \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b\n  expect(callback).toHaveBeenCalledTimes(1)\n})<\/pre>\n\n\n\n<p>\u0412 \u043e\u0441\u043e\u0431\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f&nbsp;<a href=\"https:\/\/jestjs.io\/docs\/en\/timer-mocks#run-pending-timers\">jest.runOnlyPendingTimers()<\/a>.<\/p>\n\n\n\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435:&nbsp;<code>jest.useFakeTimers()<\/code>&nbsp;\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0444\u0438\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432.<\/p>\n\n\n\n<h2>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n\n\n\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0442\u0435\u0441\u0442\u044b \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">test.each([[3, 2, 1], [1, 2, 3], [2, 1, 3]])('.add(%s, %s)', (a, b, expected) =&gt; {\n  expect(a + b).toBe(expected)\n})<\/pre>\n\n\n\n<p>\u0418\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0445 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u0432:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">test.each`\n  a    | b    | expected\n${3} | ${2} | ${1}\n${1} | ${2} | ${3}\n${2} | ${1} | ${3}\n`('\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 $expected \u043f\u0440\u0438 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0438 $a \u0438 $b', ({ a, b, expected }) =&gt; {\n  expect(a + b).toBe(expected)\n})<\/pre>\n\n\n\n<p>\u0418\u043b\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435&nbsp;<code>describe<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">describe.each([['mobile'], ['tablet'], ['desktop']])('\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430 %s', (viewport) =&gt; {\n  test('\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b', () =&gt; {\n    \/\/\n  })\n})<\/pre>\n\n\n\n<p><a href=\"https:\/\/jestjs.io\/docs\/en\/api.html#describeeachtablename-fn-timeout\">describe.each()<\/a>,&nbsp;<a href=\"https:\/\/jestjs.io\/docs\/en\/api.html#testeachtablename-fn-timeout\">test.each()<\/a><\/p>\n\n\n\n<h2>\u041f\u0440\u043e\u043f\u0443\u0441\u043a \u0442\u0435\u0441\u0442\u043e\u0432. \u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e Jest.<\/h2>\n\n\n\n<p>\u041d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">describe.skip('makePoniesPink'...\ntests.skip('\u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043d\u0438 \u0440\u043e\u0437\u043e\u0432\u044b\u043c'...<\/pre>\n\n\n\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">describe.only('makePoniesPink'...\ntests.only('\u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043d\u0438 \u0440\u043e\u0437\u043e\u0432\u044b\u043c'...<\/pre>\n\n\n\n<h2>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0441 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u043c\u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0430\u043c\u0438<\/h2>\n\n\n\n<p>Node.js \u0438 Jest will \u043a\u044d\u0448\u0438\u0440\u0443\u044e\u0442 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0435 (<code>require<\/code>) \u043c\u043e\u0434\u0443\u043b\u0438. \u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0441 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u043c\u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0430\u043c\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0447\u0438\u0449\u0430\u0442\u044c \u0440\u0435\u0435\u0441\u0442\u0440 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u043c\u0435\u0436\u0434\u0443 \u0442\u0435\u0441\u0442\u0430\u043c\u0438:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const modulePath = '..\/module-to-test'\n\nafterEach(() =&gt; {\n  jest.resetModules()\n})\n\ntest('\u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0435\u0441\u0442', () =&gt; {\n  \/\/ \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430\n  const result = require(modulePath)\n  expect(result).toMatchSnapshot()\n})\n\ntest('\u0432\u0442\u043e\u0440\u043e\u0439 \u0442\u0435\u0441\u0442', () =&gt; {\n  \/\/ \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430\n  const fn = () =&gt; require(modulePath)\n  expect(fn).toThrow()\n})<\/pre>\n\n\n\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u2014 <a href=\"https:\/\/bookflow.ru\/shpargalka-po-react-otvety-na-voprosy-2020-2021\/\">\u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e React- \u043e\u0442\u0432\u0435\u0442\u044b \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b 2020-2021<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e Jest (Stylesheet Jest)<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[30],"tags":[195,65],"_links":{"self":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts\/2363"}],"collection":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2363"}],"version-history":[{"count":1,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts\/2363\/revisions"}],"predecessor-version":[{"id":2364,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts\/2363\/revisions\/2364"}],"wp:attachment":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}