Skip to content

Commit 61d37a3

Browse files
authored
chore: Jest updates to support Filter Packages (#2246)
1 parent fa40416 commit 61d37a3

File tree

13 files changed

+58
-77
lines changed

13 files changed

+58
-77
lines changed

__mocks__/i18next.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

__mocks__/react-i18next.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,24 @@
2323
SOFTWARE.
2424
2525
*/
26-
export const useTranslation = () => {
27-
return {
28-
t: (key: string, options: { [key: string]: string }) => {
29-
return `${key} ${
30-
options
31-
? Object.keys(options)
32-
.map((optionsKey) =>
33-
optionsKey === 'ns' ? '' : options[optionsKey]
34-
)
35-
.join(' ')
36-
: ''
37-
}`
38-
},
39-
}
40-
}
26+
export const useTranslation = () => ({
27+
t: (key, options) =>
28+
[
29+
key,
30+
...(options
31+
? Object.keys(options).map((optionsKey) =>
32+
optionsKey === 'ns' ? '' : options[optionsKey]
33+
)
34+
: []),
35+
]
36+
.join(' ')
37+
.trim()
38+
.replace(/\s+/g, ' '),
39+
})
4140

42-
export const initReactI18next = jest.fn()
41+
export const initReactI18next = {
42+
init: () => {
43+
//
44+
},
45+
type: '3rdParty',
46+
}

jest.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
SOFTWARE.
2424
2525
*/
26-
process.env.TZ = 'UTC'
26+
process.env.TZ = 'PST8PDT'
2727

2828
module.exports = {
2929
automock: false,
@@ -41,7 +41,8 @@ module.exports = {
4141
moduleDirectories: ['./node_modules', './packages'],
4242
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json', 'node'],
4343
moduleNameMapper: {
44-
'@looker/([^/]+)$': '<rootDir>/packages/$1/src',
44+
'@looker/components/lib/date': '<rootDir>/packages/components/src/date',
45+
'@looker\\/((?!sdk)[^\\/]+)': '<rootDir>/packages/$1/src',
4546
'\\.(css)$': '<rootDir>/config/jest/styleMock.js',
4647
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
4748
'<rootDir>/config/jest/fileMock.js',

jest.setup.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ globalAny.IntersectionObserver = observeMock
4242
// js-dom doesn't do scrollIntoView
4343
Element.prototype.scrollIntoView = jest.fn()
4444

45-
// Ensure jest viewport has real dimensions to support responsively rendering content
46-
Object.defineProperty(document.body, 'clientWidth', {
47-
value: 800, // match storyshots default viewport
48-
})
49-
50-
Object.defineProperty(document.body, 'clientHeight', {
51-
value: 600, // match storyshots default viewport
52-
})
53-
5445
/**
5546
* Throw a hard-error if an underlying library (e.g.: React) is throwing console.error
5647
* Inspired by: https://github.com/facebook/jest/issues/6121#issuecomment-529591574

packages/components-providers/src/I18n/useI18n.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@ const TestComponent = (props: UseI18nProps) => {
3737

3838
describe('useI18n', () => {
3939
test('initializes i18next', () => {
40+
const spy = jest.spyOn(i18next, 'init')
4041
render(<TestComponent />)
4142
expect(i18next.init).toHaveBeenCalledTimes(1)
43+
spy.mockRestore()
4244
})
4345

4446
test('updates with new props', () => {
47+
const spy = jest.spyOn(i18next, 'addResourceBundle')
4548
i18next.isInitialized = true
4649
render(<TestComponent />)
4750
expect(i18next.addResourceBundle).toHaveBeenCalledTimes(
4851
Object.keys(i18nResources.en).length
4952
)
53+
spy.mockRestore()
5054
})
5155
})

packages/components/src/Breakpoint/Breakpoint.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ import { Breakpoint } from './Breakpoint'
3838
*/
3939

4040
describe('Breakpoint', () => {
41+
let widthSpy: jest.SpyInstance<number, []>
42+
let heightSpy: jest.SpyInstance<number, []>
43+
44+
beforeEach(() => {
45+
widthSpy = jest
46+
.spyOn(document.body, 'clientWidth', 'get')
47+
.mockImplementation(() => 800)
48+
heightSpy = jest
49+
.spyOn(document.body, 'clientHeight', 'get')
50+
.mockImplementation(() => 600)
51+
})
52+
afterEach(() => {
53+
widthSpy.mockRestore()
54+
heightSpy.mockRestore()
55+
})
56+
4157
test('all', () => {
4258
renderWithTheme(
4359
<Breakpoint show={['mobile', 'xl']}>

packages/components/src/Calendar/CalendarNav.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const realDateNow = Date.now.bind(global.Date)
3636

3737
beforeEach(() => {
3838
/* eslint-disable-next-line @typescript-eslint/unbound-method */
39-
global.Date.now = jest.fn(() => 1580517818172)
39+
global.Date.now = jest.fn(() => 1580567580000)
4040
})
4141

4242
afterEach(() => {

packages/components/src/DateTimeFormat/DateTimeFormat.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('DateTimeFormat', () => {
5757
)
5858
expect(container).toMatchInlineSnapshot(`
5959
<div>
60-
Jan 25, 1988, 5:28:03 PM GMT+5:30
60+
Jan 26, 1988, 1:28:03 AM GMT+5:30
6161
</div>
6262
`)
6363
})
@@ -79,7 +79,7 @@ describe('DateTimeFormat', () => {
7979
)
8080
expect(container).toMatchInlineSnapshot(`
8181
<div>
82-
January 25th, 1988 at 11:58:03 AM GMT+0
82+
January 25th, 1988 at 11:58:03 AM GMT-8
8383
</div>
8484
`)
8585
})
@@ -90,7 +90,7 @@ describe('DateTimeFormat', () => {
9090
)
9191
expect(container).toMatchInlineSnapshot(`
9292
<div>
93-
Monday, January 25th, 1988 at 11:58:03 AM GMT+00:00
93+
Monday, January 25th, 1988 at 11:58:03 AM GMT-08:00
9494
</div>
9595
`)
9696
})

packages/components/src/Form/Fields/FieldDate/FieldDate.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const realDateNow = Date.now.bind(global.Date)
3434

3535
beforeEach(() => {
3636
/* eslint-disable-next-line @typescript-eslint/unbound-method */
37-
global.Date.now = jest.fn(() => 1580517818172)
37+
global.Date.now = jest.fn(() => 1580567580000)
3838
})
3939

4040
afterEach(() => {

packages/components/src/Form/Fields/FieldDateRange/FieldDateRange.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const realDateNow = Date.now.bind(global.Date)
3434

3535
beforeEach(() => {
3636
/* eslint-disable-next-line @typescript-eslint/unbound-method */
37-
global.Date.now = jest.fn(() => 1580517818172)
37+
global.Date.now = jest.fn(() => 1580567580000)
3838
})
3939

4040
afterEach(() => {

0 commit comments

Comments
 (0)