From 323dc4d59d8f20468a92d157d6247944b664a94a Mon Sep 17 00:00:00 2001 From: jpina1 Date: Thu, 4 Jan 2024 12:01:12 -0800 Subject: [PATCH] tests: refactor --- packages/gasket-react-intl/test/utils.test.js | 18 ++++----- .../test/with-intl-provider.test.js | 28 ++++++------- .../test/with-locale-required.test.js | 40 +++++++++---------- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/packages/gasket-react-intl/test/utils.test.js b/packages/gasket-react-intl/test/utils.test.js index b36a5ba32..798d656de 100644 --- a/packages/gasket-react-intl/test/utils.test.js +++ b/packages/gasket-react-intl/test/utils.test.js @@ -7,31 +7,31 @@ jest.mock('../src/config', () => ({ manifest: require('./fixtures/mock-manifest.json') })); -describe('utils', () => { +describe('utils', function () { let mockConfig; - beforeEach(() => { + beforeEach(function () { mockConfig = require('../src/config'); }); - afterEach(() => { + afterEach(function () { jest.restoreAllMocks(); delete global.window.gasketIntlLocale; delete global.navigator.languages; }); - it('exports localeUtils instance', () => { + it('exports localeUtils instance', function () { expect(utils).toHaveProperty('localeUtils'); expect(utils.localeUtils).toBeInstanceOf(LocaleUtils); }); - describe('getActiveLocale', () => { - it('returns defaultLocale from manifest', () => { + describe('getActiveLocale', function () { + it('returns defaultLocale from manifest', function () { const results = utils.getActiveLocale(); expect(results).toEqual(mockConfig.manifest.defaultLocale); }); - it('returns locale from window property', () => { + it('returns locale from window property', function () { mockConfig.isBrowser = true; mockConfig.clientData.locale = 'fr'; global.window.gasketIntlLocale = 'de'; @@ -43,7 +43,7 @@ describe('utils', () => { expect(results).toEqual('de'); }); - it('returns locale from clientData', () => { + it('returns locale from clientData', function () { mockConfig.isBrowser = true; mockConfig.clientData.locale = 'fr'; Object.defineProperty(global.navigator, 'languages', { @@ -54,7 +54,7 @@ describe('utils', () => { expect(results).toEqual('fr'); }); - it('returns locale from first navigator.languages', () => { + it('returns locale from first navigator.languages', function () { mockConfig.isBrowser = true; mockConfig.clientData.locale = null; Object.defineProperty(global.navigator, 'languages', { diff --git a/packages/gasket-react-intl/test/with-intl-provider.test.js b/packages/gasket-react-intl/test/with-intl-provider.test.js index 516f2b92f..08e1bf0f0 100644 --- a/packages/gasket-react-intl/test/with-intl-provider.test.js +++ b/packages/gasket-react-intl/test/with-intl-provider.test.js @@ -9,21 +9,21 @@ const MockComponent = class extends React.Component { } }; -describe('withIntlProvider', () => { +describe('withIntlProvider', function () { let mockConfig; let withIntlProvider; - beforeEach(() => { + beforeEach(function () { mockConfig = require('../src/config'); withIntlProvider = withIntlProviderDefault(); }); - it('adds display name', () => { + it('adds display name', function () { const WrappedComponent = withIntlProvider(MockComponent); expect(WrappedComponent.displayName).toBe('withIntlProvider(MockComponent)'); }); - it('hoists non-react statics', () => { + it('hoists non-react statics', function () { const WrappedComponent = withIntlProvider(MockComponent); expect(WrappedComponent).not.toHaveProperty('bogus'); MockComponent.bogus = 'BOGUS'; @@ -32,7 +32,7 @@ describe('withIntlProvider', () => { delete MockComponent.bogus; }); - it('hoists getInitialProps if set', () => { + it('hoists getInitialProps if set', function () { const WrappedComponent = withIntlProvider(MockComponent); expect(WrappedComponent).not.toHaveProperty('getInitialProps'); MockComponent.getInitialProps = f => f; @@ -41,17 +41,17 @@ describe('withIntlProvider', () => { delete MockComponent.getInitialProps; }); - describe('reducer', () => { + describe('reducer', function () { let initState; - beforeEach(() => { + beforeEach(function () { initState = { messages: { en: { first: 'First' } }, status: { '/locales/en/first.json': LOADED } }; }); - it('LOADED actions add messages and file status', () => { + it('LOADED actions add messages and file status', function () { const action = { type: LOADED, payload: { locale: 'en', messages: { example: 'Example' }, file: '/locales/en.json' } }; const result = reducer(initState, action); expect(result).toEqual({ @@ -68,7 +68,7 @@ describe('withIntlProvider', () => { }); }); - it('ERROR actions add file status', () => { + it('ERROR actions add file status', function () { const action = { type: ERROR, payload: { file: '/locales/en.json' } }; const result = reducer(initState, action); expect(result).toEqual({ @@ -84,7 +84,7 @@ describe('withIntlProvider', () => { }); }); - it('LOADING actions add file status', () => { + it('LOADING actions add file status', function () { const action = { type: LOADING, payload: { file: '/locales/en.json' } }; const result = reducer(initState, action); expect(result).toEqual({ @@ -101,8 +101,8 @@ describe('withIntlProvider', () => { }); }); - describe('init', () => { - it('initializes state with empty objects', () => { + describe('init', function () { + it('initializes state with empty objects', function () { const result = init({}); expect(result).toEqual({ messages: {}, @@ -110,7 +110,7 @@ describe('withIntlProvider', () => { }); }); - it('initializes state with locales props', () => { + it('initializes state with locales props', function () { const result = init({ locale: 'en', messages: { en: { example: 'Example' } }, @@ -122,7 +122,7 @@ describe('withIntlProvider', () => { }); }); - it('merges locales props data with client data', () => { + it('merges locales props data with client data', function () { mockConfig.clientData = { locale: 'en', messages: { en: { first: 'First' } }, diff --git a/packages/gasket-react-intl/test/with-locale-required.test.js b/packages/gasket-react-intl/test/with-locale-required.test.js index 2283119fa..2a0d1c743 100644 --- a/packages/gasket-react-intl/test/with-locale-required.test.js +++ b/packages/gasket-react-intl/test/with-locale-required.test.js @@ -15,7 +15,7 @@ const MockComponent = class extends React.Component { } }; -describe('withLocaleRequired', () => { +describe('withLocaleRequired', function () { let useLocaleRequiredMock, wrapper; const doMount = (...args) => { @@ -23,25 +23,25 @@ describe('withLocaleRequired', () => { return render(); }; - beforeEach(() => { + beforeEach(function () { useLocaleRequiredMock = require('../src/use-locale-required'); }); - afterEach(() => { + afterEach(function () { jest.restoreAllMocks(); }); - it('adds display name', () => { + it('adds display name', function () { const wrapped = withLocaleRequired()(MockComponent); expect(wrapped.displayName).toBe('withLocaleRequired(MockComponent)'); }); - it('adds display name with ForwardRef', () => { + it('adds display name with ForwardRef', function () { const wrapped = withLocaleRequired('/locales', { forwardRef: true })(MockComponent); expect(wrapped.displayName).toBe('ForwardRef(withLocaleRequired/MockComponent))'); }); - it('hoists non-react statics', () => { + it('hoists non-react statics', function () { const wrapped = withLocaleRequired()(MockComponent); expect(wrapped).not.toHaveProperty('bogus'); MockComponent.bogus = 'BOGUS'; @@ -50,12 +50,12 @@ describe('withLocaleRequired', () => { delete MockComponent.bogus; }); - describe('#getInitialProps', () => { - afterEach(() => { + describe('#getInitialProps', function () { + afterEach(function () { delete MockComponent.getInitialProps; }); - it('hoists getInitialProps if set', () => { + it('hoists getInitialProps if set', function () { const wrapped = withLocaleRequired()(MockComponent); expect(wrapped).not.toHaveProperty('getInitialProps'); MockComponent.getInitialProps = jest.fn(); @@ -63,12 +63,12 @@ describe('withLocaleRequired', () => { expect(wrappedGetInitialProps).toHaveProperty('getInitialProps'); }); - it('adds getInitialProps if initialProps set', () => { + it('adds getInitialProps if initialProps set', function () { const wrapped = withLocaleRequired('/locales', { initialProps: true })(MockComponent); expect(wrapped).toHaveProperty('getInitialProps'); }); - it('executes wrapped getInitialProps', async () => { + it('executes wrapped getInitialProps', async function () { MockComponent.getInitialProps = jest.fn().mockResolvedValue({ bogus: true }); const wrapped = withLocaleRequired('/locales', { initialProps: true })(MockComponent); const ctx = {}; @@ -77,7 +77,7 @@ describe('withLocaleRequired', () => { expect(props).toEqual({ bogus: true }); }); - it('loads localeProps on server', async () => { + it('loads localeProps on server', async function () { MockComponent.getInitialProps = jest.fn().mockResolvedValue({ bogus: true }); const wrapped = withLocaleRequired('/locales', { initialProps: true })(MockComponent); const ctx = { @@ -104,7 +104,7 @@ describe('withLocaleRequired', () => { }); }); - it('handles missing gasketData', async () => { + it('handles missing gasketData', async function () { MockComponent.getInitialProps = jest.fn().mockResolvedValue({ bogus: true }); const wrapped = withLocaleRequired('/locales', { initialProps: true })(MockComponent); const ctx = { @@ -123,7 +123,7 @@ describe('withLocaleRequired', () => { expect(error).toBe(null); }); - it('resolve localePahThunk and passes as prop', async () => { + it('resolve localePahThunk and passes as prop', async function () { const mockThunk = jest.fn().mockImplementation((context) => (context.extra ? '/locales/extra' : '/locales')); MockComponent.getInitialProps = jest.fn().mockResolvedValue({ bogus: true }); const wrapped = withLocaleRequired(mockThunk, { initialProps: true })(MockComponent); @@ -154,35 +154,35 @@ describe('withLocaleRequired', () => { }); }); - describe('#render', () => { - it('renders empty if loading', () => { + describe('#render', function () { + it('renders empty if loading', function () { useLocaleRequiredMock.mockReturnValue(LOADING); // Set the mock return value to LOADING; wrapper = doMount(); expect(wrapper.baseElement.innerHTML).toEqual('
'); }); - it('renders custom loader if loading', async () => { + it('renders custom loader if loading', async function () { useLocaleRequiredMock.mockReturnValue(LOADING); doMount('/locales', { loading: loadingText }); const textEl = await screen.findByText(loadingText); expect(textEl.innerHTML).toEqual(loadingText); }); - it('renders wrapped component if LOADED', async () => { + it('renders wrapped component if LOADED', async function () { useLocaleRequiredMock.mockReturnValue(LOADED); doMount({ loading: loadingText }); const textEl = await screen.findByText('MockComponent'); expect(textEl.innerHTML).toEqual('MockComponent'); }); - it('renders wrapped component if ERROR', async () => { + it('renders wrapped component if ERROR', async function () { useLocaleRequiredMock.mockReturnValue(ERROR); doMount({ loading: loadingText }); const textEl = await screen.findByText('MockComponent'); expect(textEl.innerHTML).toEqual('MockComponent'); }); - it('forwards refs', async () => { + it('forwards refs', async function () { class TestComponent extends React.Component { // Used to test ref forwarding getMockData() {