Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Apr 29, 2020
1 parent 0e0b2bb commit 7b1211a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 34 deletions.
10 changes: 7 additions & 3 deletions test/composer.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */

// utils
jest.mock('../src/utils', () => ({
...jest.requireActual('../src/utils'),
Expand Down Expand Up @@ -287,7 +289,7 @@ describe('fallbackFormat', () => {

test('interpolation', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const { t } = createComposer({
locale: 'en',
Expand Down Expand Up @@ -344,13 +346,13 @@ describe('getMissingHandler / setMissingHandler', () => {
const { getMissingHandler, setMissingHandler } = createComposer({})
expect(getMissingHandler()).toEqual(null)

const missing = () => {} // eslint-disable-line @typescript-eslint/no-empty-function
const missing = () => {}
setMissingHandler(missing as MissingHandler)
expect(getMissingHandler()).toEqual(missing)
})

test('initialize at composer creating', () => {
const missing = () => {} // eslint-disable-line @typescript-eslint/no-empty-function
const missing = () => {}
const { getMissingHandler } = createComposer({ missing })
expect(getMissingHandler()).toEqual(missing)
})
Expand Down Expand Up @@ -713,3 +715,5 @@ describe('__i18n', () => {
})
})
})

/* eslint-enable @typescript-eslint/no-empty-function */
10 changes: 7 additions & 3 deletions test/legacy.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */

// utils
jest.mock('../src/utils', () => ({
...jest.requireActual('../src/utils'),
Expand Down Expand Up @@ -35,7 +37,7 @@ test('availableLocales', () => {

test('formatter', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const i18n = createVueI18n({
formatter: {
Expand Down Expand Up @@ -407,7 +409,7 @@ test('getNumberFormat / setNumberFormat / mergeNumberFormat', () => {

test('getChoiceIndex', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const i18n = createVueI18n({})
i18n.getChoiceIndex(1, 2)
Expand All @@ -418,7 +420,7 @@ test('getChoiceIndex', () => {

test('warnHtmlInMessage', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const i18n = createVueI18n({
locale: 'en',
Expand All @@ -438,3 +440,5 @@ test('warnHtmlInMessage', () => {
expect(i18n.t('hello')).toEqual('<p>hello</p>')
expect(mockWarn).toHaveBeenCalledTimes(2)
})

/* eslint-enable @typescript-eslint/no-empty-function */
16 changes: 10 additions & 6 deletions test/runtime/datetime.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */

// utils
jest.mock('../../src/utils', () => ({
...jest.requireActual('../../src/utils'),
Expand Down Expand Up @@ -157,7 +159,7 @@ test('override format options with number function options', () => {

test('fallback', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})
const mockAvailabilities = Availabilities as jest.Mocked<
typeof Availabilities
>
Expand All @@ -182,7 +184,7 @@ test('fallback', () => {

test(`context fallbackWarn 'false' option`, () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})
const mockAvailabilities = Availabilities as jest.Mocked<
typeof Availabilities
>
Expand All @@ -202,7 +204,7 @@ test(`context fallbackWarn 'false' option`, () => {

test(`datetime function fallbackWarn 'false' option`, () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})
const mockAvailabilities = Availabilities as jest.Mocked<
typeof Availabilities
>
Expand All @@ -224,7 +226,7 @@ test(`datetime function fallbackWarn 'false' option`, () => {
describe('context unresolving option', () => {
test('not specify fallbackLocales', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})
const mockAvailabilities = Availabilities as jest.Mocked<
typeof Availabilities
>
Expand All @@ -244,7 +246,7 @@ describe('context unresolving option', () => {

test('not found key in fallbackLocales', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})
const mockAvailabilities = Availabilities as jest.Mocked<
typeof Availabilities
>
Expand Down Expand Up @@ -292,7 +294,7 @@ test('part', () => {

test('not available Intl API', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})
const mockAvailabilities = Availabilities as jest.Mocked<
typeof Availabilities
>
Expand All @@ -309,3 +311,5 @@ test('not available Intl API', () => {
`Cannot format a Date value due to not supported Intl.DateTimeFormat.`
)
})

/* eslint-eable @typescript-eslint/no-empty-function */
16 changes: 10 additions & 6 deletions test/runtime/number.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */

// utils
jest.mock('../../src/utils', () => ({
...jest.requireActual('../../src/utils'),
Expand Down Expand Up @@ -138,7 +140,7 @@ test('override format options with number function options', () => {

test('fallback', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})
const mockAvailabilities = Availabilities as jest.Mocked<
typeof Availabilities
>
Expand All @@ -163,7 +165,7 @@ test('fallback', () => {

test(`context fallbackWarn 'false' option`, () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})
const mockAvailabilities = Availabilities as jest.Mocked<
typeof Availabilities
>
Expand All @@ -183,7 +185,7 @@ test(`context fallbackWarn 'false' option`, () => {

test(`number function fallbackWarn 'false' option`, () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})
const mockAvailabilities = Availabilities as jest.Mocked<
typeof Availabilities
>
Expand All @@ -205,7 +207,7 @@ test(`number function fallbackWarn 'false' option`, () => {
describe('context unresolving option', () => {
test('not specify fallbackLocales', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})
const mockAvailabilities = Availabilities as jest.Mocked<
typeof Availabilities
>
Expand All @@ -225,7 +227,7 @@ describe('context unresolving option', () => {

test('not found key in fallbackLocales', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})
const mockAvailabilities = Availabilities as jest.Mocked<
typeof Availabilities
>
Expand Down Expand Up @@ -268,7 +270,7 @@ test('part', () => {

test('not available Intl API', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})
const mockAvailabilities = Availabilities as jest.Mocked<
typeof Availabilities
>
Expand All @@ -285,3 +287,5 @@ test('not available Intl API', () => {
`Cannot format a Date value due to not supported Intl.NumberFormat.`
)
})

/* eslint-enable @typescript-eslint/no-empty-function */
36 changes: 20 additions & 16 deletions test/runtime/translate.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */

// utils
jest.mock('../../src/utils', () => ({
...jest.requireActual('../../src/utils'),
Expand Down Expand Up @@ -113,7 +115,7 @@ describe('default option', () => {
describe('context missing option', () => {
test('not specified missing handler', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand All @@ -130,7 +132,7 @@ describe('context missing option', () => {

test('specified missing handler', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand All @@ -151,7 +153,7 @@ describe('context missing option', () => {
describe('context missingWarn option', () => {
test('false', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand All @@ -168,7 +170,7 @@ describe('context missingWarn option', () => {

test('regex', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand All @@ -189,7 +191,7 @@ describe('context missingWarn option', () => {

test('missingWarn option', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand All @@ -207,7 +209,7 @@ describe('context missingWarn option', () => {
describe('context fallbackWarn option', () => {
test('not specify fallbackLocale', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand All @@ -223,7 +225,7 @@ describe('context fallbackWarn option', () => {

test('specify fallbackLocale', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand All @@ -246,7 +248,7 @@ describe('context fallbackWarn option', () => {

test('not found fallback message', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand All @@ -270,7 +272,7 @@ describe('context fallbackWarn option', () => {

test('context option: false', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand All @@ -289,7 +291,7 @@ describe('context fallbackWarn option', () => {

test('context option: regex', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand All @@ -308,7 +310,7 @@ describe('context fallbackWarn option', () => {

test('specify fallbackWarn option to translate function', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand All @@ -331,7 +333,7 @@ describe('context fallbackWarn option', () => {
describe('context fallbackFormat option', () => {
test('specify true', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand Down Expand Up @@ -367,7 +369,7 @@ describe('context fallbackFormat option', () => {

test('overrided with default option', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand Down Expand Up @@ -403,7 +405,7 @@ describe('context fallbackFormat option', () => {

test('fallbackLocales is nothing', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand Down Expand Up @@ -456,7 +458,7 @@ describe('context unresolving option', () => {

test('fallbackFormat is true', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand Down Expand Up @@ -530,7 +532,7 @@ describe('context postTranslation option', () => {
describe('warnHtmlMessage', () => {
test('default', () => {
const mockWarn = warn as jest.MockedFunction<typeof warn>
mockWarn.mockImplementation(() => {}) // eslint-disable-line @typescript-eslint/no-empty-function
mockWarn.mockImplementation(() => {})

const ctx = context({
locale: 'en',
Expand Down Expand Up @@ -571,3 +573,5 @@ describe('edge cases', () => {
expect(translate(ctx, 'side.left')).toEqual('Left')
})
})

/* eslint-enable @typescript-eslint/no-empty-function */

0 comments on commit 7b1211a

Please sign in to comment.