@navinc/base-react-components
Version:
Nav's Pattern Library
52 lines (47 loc) • 1.53 kB
JavaScript
import useTealiumUtag, { waitForTealium } from './use-tealium-utag'
import { renderHook } from '@testing-library/react-hooks'
import { act } from '@testing-library/react'
describe('useTealiumUtag', () => {
it('should return object with tealiumID of "1234"', async () => {
global.utag = {
data: {
tealium_visitor_id: '1234',
},
}
const { result, waitForNextUpdate } = renderHook(() => useTealiumUtag())
await act(async () => {
await waitForNextUpdate()
})
expect(result.current.tealiumId).toBe('1234')
expect(result.current.loading).toBe(false)
})
it('should return object with tealiumID of undefined and loading is false after 3 seconds of waiting', async () => {
global.utag = {
data: {},
}
const { result, waitForNextUpdate } = renderHook(() => useTealiumUtag())
await act(async () => {
await waitForNextUpdate({ timeout: 3000 })
})
expect(result.current.tealiumId).toBe(undefined)
expect(result.current.loading).toBe(false)
})
})
describe('waitForTealium', () => {
it('should return object with tealiumID of "1234"', async () => {
global.utag = {
data: {
tealium_visitor_id: '1234',
},
}
const res = await waitForTealium()
expect(res.tealium_visitor_id).toBe('1234')
})
it('should return object with tealiumID of undefined', async () => {
global.utag = {
data: {},
}
const res = await waitForTealium()
expect(res.tealium_visitor_id).toBe(undefined)
})
})