From 0fdc7980f5cacfc92b7f37ddbba907415a080294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD=20=D0=90=D0=BB=D0=B5=CC=88?= =?UTF-8?q?=D1=88=D0=B8=D0=BD?= Date: Wed, 12 May 2021 16:26:01 +0300 Subject: [PATCH] SBERDOMA-108 test case of correct rendering for BehaviourRecorder Mocked Next Config for test environment, as suggested here: https://github.com/vercel/next.js/issues/9761#issuecomment-721048254 --- .../containers/BehaviourRecorder.test.js | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/apps/condo/domains/common/components/containers/BehaviourRecorder.test.js b/apps/condo/domains/common/components/containers/BehaviourRecorder.test.js index f73ea9540ca..46c505f9342 100644 --- a/apps/condo/domains/common/components/containers/BehaviourRecorder.test.js +++ b/apps/condo/domains/common/components/containers/BehaviourRecorder.test.js @@ -1,7 +1,6 @@ -// import TestRenderer from 'react-test-renderer'; +import TestRenderer from 'react-test-renderer' import BehaviorRecorder, { htmlFor, parseParamsFor } from './BehaviorRecorder' - const CORRECT_PLERDY_PARAMS = '{"site_hash_code": "1234567890abcdefghijklmnopqrstyv", "suid": 12345}' const CORRECT_PLERDY_PARSED_PARAMS = { @@ -9,24 +8,42 @@ const CORRECT_PLERDY_PARSED_PARAMS = { suid: 12345, } +jest.mock('next/config', () => () => ({ + publicRuntimeConfig: { + behaviorRecorder: { + plerdy: CORRECT_PLERDY_PARAMS, + }, + }, +})) + const CORRECT_PLERDY_HTML = '' describe('BehaviorRecorder', () => { describe('plerdy', () => { - // TODO(antonal): figure out how to fetch Next.js Config in Test environment - // TypeError: Cannot destructure property 'publicRuntimeConfig' of '(0 , _config.default)(...)' as it is undefined. - // it('renders correctly', () => { + it('renders html in div for correct config params', () => { + const result = TestRenderer.create( + + ) + expect(result.toJSON()).toMatchObject({ + type: 'div', + props: { + dangerouslySetInnerHTML: { + __html: CORRECT_PLERDY_HTML, + }, + }, + }) + }) + + // TODO(antonal): figure out how to mock Next Config for each test case + // When we call `jest.mock` inside of test case, it throws an error: + // >> The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables. + + // it('renders null for incorrect config params', () => { // const result = TestRenderer.create( // // ) - // expect(result.toJSON()).toMatchObject({ - // type: 'div', - // props: { - // engine: 'plerdy' - // }, - // children: CORRECT_PLERDY_HTML - // }) + // expect(result).toBeNull() // }) describe('injectParamsFor', () => {