mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-18 09:20:34 +03:00
test: add e2e tests
fix: boolean attributes client side
This commit is contained in:
committed by
Alexander Lichter
parent
a853ce3de7
commit
05b8891110
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* @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()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user