-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PFX-444] - Convert react intl tests to jest (#646)
* tests: converted utils to jest * tests: with-intil-provider to jest * tests: convert with-locale-required to jest * tests: convert locale-requied to jest * tests: convert use-locale-required to jest * tests: convert next.test to jest * tests: refactor
- Loading branch information
1 parent
de5967f
commit 252cbf9
Showing
9 changed files
with
248 additions
and
279 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
collectCoverageFrom: ['lib/**/*.js'], | ||
setupFiles: ['<rootDir>/test/setup.js'], | ||
testEnvironment: 'jsdom' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,60 @@ | ||
import React from 'react'; | ||
import assume from 'assume'; | ||
import sinon from 'sinon'; | ||
import proxyquire from 'proxyquire'; | ||
import { render } from '@testing-library/react'; | ||
import mockManifest from './fixtures/mock-manifest.json'; | ||
import { LocaleStatus } from '../src/utils'; | ||
import LocaleRequired from '../src/locale-required'; | ||
import useLocaleRequired from '../src/use-locale-required'; | ||
|
||
jest.mock('../src/use-locale-required'); | ||
|
||
const { ERROR, LOADED, LOADING } = LocaleStatus; | ||
|
||
describe('LocaleRequired', function () { | ||
let mockConfig, useLocaleRequiredStub, LocaleRequired, wrapper; | ||
let wrapper; | ||
|
||
const doMount = props => <LocaleRequired { ...props }>MockComponent</LocaleRequired>; | ||
|
||
beforeEach(function () { | ||
useLocaleRequiredStub = sinon.stub(); | ||
mockConfig = { | ||
defaultLocale: 'en-US', | ||
manifest: { ...mockManifest, paths: { ...mockManifest.paths } }, | ||
isBrowser: false | ||
}; | ||
LocaleRequired = proxyquire('../src/locale-required', { | ||
'./config': mockConfig, | ||
'./use-locale-required': { | ||
default: useLocaleRequiredStub | ||
} | ||
}).default; | ||
}); | ||
|
||
afterEach(function () { | ||
sinon.restore(); | ||
useLocaleRequired.mockClear(); | ||
}); | ||
|
||
describe('#render', function () { | ||
it('renders null if loading', function () { | ||
useLocaleRequiredStub.returns(LOADING); | ||
useLocaleRequired.mockReturnValue(LOADING); | ||
wrapper = render(doMount({})); | ||
assume(wrapper.baseElement.textContent).eqls(''); | ||
expect(wrapper.baseElement.textContent).toEqual(''); | ||
}); | ||
|
||
it('renders custom loader if loading', function () { | ||
useLocaleRequiredStub.returns(LOADING); | ||
useLocaleRequired.mockReturnValue(LOADING); | ||
wrapper = render(doMount({ loading: 'loading...' })); | ||
assume(wrapper.baseElement.textContent).eqls('loading...'); | ||
expect(wrapper.baseElement.textContent).toEqual('loading...'); | ||
}); | ||
|
||
it('renders wrapped component if LOADED', function () { | ||
useLocaleRequiredStub.returns(LOADED); | ||
useLocaleRequired.mockReturnValue(LOADED); | ||
wrapper = render(doMount({ loading: 'loading...' })); | ||
assume(wrapper.baseElement.textContent).includes('MockComponent'); | ||
expect(wrapper.baseElement.textContent).toContain('MockComponent'); | ||
}); | ||
|
||
it('renders wrapped component if ERROR', function () { | ||
useLocaleRequiredStub.returns(ERROR); | ||
useLocaleRequired.mockReturnValue(ERROR); | ||
wrapper = render(doMount({ loading: 'loading...' })); | ||
assume(wrapper.baseElement.textContent).includes('MockComponent'); | ||
expect(wrapper.baseElement.textContent).toContain('MockComponent'); | ||
}); | ||
|
||
it('supports localesPath', function () { | ||
useLocaleRequiredStub.returns(LOADING); | ||
useLocaleRequired.mockReturnValue(LOADING); | ||
wrapper = render(doMount({ localesPath: '/bogus' })); | ||
assume(useLocaleRequiredStub).calledWith('/bogus'); | ||
assume(wrapper.baseElement.textContent).eqls(''); | ||
expect(useLocaleRequired).toHaveBeenCalledWith('/bogus'); | ||
expect(wrapper.baseElement.textContent).toEqual(''); | ||
}); | ||
|
||
it('supports localesPath as thunk', function () { | ||
const mockThunk = sinon.stub(); | ||
useLocaleRequiredStub.returns(LOADING); | ||
const mockThunk = jest.fn(); | ||
useLocaleRequired.mockReturnValue(LOADING); | ||
wrapper = render(doMount({ localesPath: mockThunk })); | ||
assume(useLocaleRequiredStub).calledWith(mockThunk); | ||
assume(wrapper.baseElement.textContent).eqls(''); | ||
expect(useLocaleRequired).toHaveBeenCalledWith(mockThunk); | ||
expect(wrapper.baseElement.textContent).toEqual(''); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.