mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-05-25 08:54:04 +03:00
05b8891110
fix: boolean attributes client side
65 lines
1.7 KiB
JavaScript
65 lines
1.7 KiB
JavaScript
/**
|
|
* @jest-environment node
|
|
*/
|
|
import { ensureIsArray } from '../../src/shared/ensure'
|
|
import setOptions from '../../src/shared/options'
|
|
import { hasGlobalWindowFn } from '../../src/shared/window'
|
|
import { defaultOptions } from '../utils/constants'
|
|
|
|
const noop = () => {}
|
|
|
|
describe('shared', () => {
|
|
test('ensureIsArray ensures var is array', () => {
|
|
let a = { p: 1 }
|
|
expect(ensureIsArray(a)).toEqual([])
|
|
|
|
a = 1
|
|
expect(ensureIsArray(a)).toEqual([])
|
|
|
|
a = [1]
|
|
expect(ensureIsArray(a)).toBe(a)
|
|
})
|
|
|
|
test('ensureIsArray ensures obj prop is array', () => {
|
|
const a = { p: 1 }
|
|
expect(ensureIsArray(a, 'p')).toEqual({ p: [] })
|
|
})
|
|
|
|
test('no error when window is not defined', () => {
|
|
expect(hasGlobalWindowFn()).toBe(false)
|
|
})
|
|
|
|
test('can use setOptions', () => {
|
|
const keyName = 'MY KEY'
|
|
let options = { keyName }
|
|
options = setOptions(options)
|
|
|
|
expect(options.keyName).toBe(keyName)
|
|
expect(options.contentKeyName).toBeDefined()
|
|
expect(options.contentKeyName).toBe(defaultOptions.contentKeyName)
|
|
})
|
|
|
|
test('setOptions warns when afterNavigation not fn', () => {
|
|
const warn = jest.spyOn(console, 'warn').mockImplementation(noop)
|
|
|
|
let options = { afterNavigation: true }
|
|
options = setOptions(options)
|
|
|
|
expect(warn).toHaveBeenCalledTimes(1)
|
|
expect(options.afterNavigation).toBeUndefined()
|
|
|
|
warn.mockRestore()
|
|
})
|
|
test('setOptions sets refreshOnceOnNavigation when afterNavigation defined', () => {
|
|
const warn = jest.spyOn(console, 'warn').mockImplementation(noop)
|
|
|
|
let options = { afterNavigation: noop }
|
|
options = setOptions(options)
|
|
|
|
expect(warn).not.toHaveBeenCalled()
|
|
expect(options.refreshOnceOnNavigation).toBe(true)
|
|
|
|
warn.mockRestore()
|
|
})
|
|
})
|