Skip to content

Commit 8bfba2c

Browse files
committed
refactor(useCookie): Simplify useCookie test
1 parent 3d2454a commit 8bfba2c

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

src/components/useCookie/useCookie.spec.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { mount } from '@src/helpers/test'
22
import { useCookie } from '@src/vue-use-kit'
3-
import { computed } from '@src/api'
43

54
afterEach(() => {
65
document.cookie = ''
@@ -16,7 +15,9 @@ const testComponent = (
1615
template: `
1716
<div>
1817
<div id="cookie">{{ cookie }}</div>
19-
<div id="cookieJson">{{ cookieValue1 }} - {{ cookieValue2 }}</div>
18+
<div id="cookieJson">
19+
{{ cookie && cookie.value1 }} - {{ cookie && cookie.value2 }}
20+
</div>
2021
<button id="getCookie" @click="getCookie"></button>
2122
<button id="setCookie" @click="setCookie(cookieValue)"></button>
2223
<button id="removeCookie" @click="removeCookie"></button>
@@ -29,24 +30,12 @@ const testComponent = (
2930
onMount
3031
)
3132

32-
const isObj = (objToCheck: any) =>
33-
Object.prototype.toString.call(objToCheck) === '[object Object]'
34-
35-
const cookieValue1 = computed(
36-
() => isObj(cookie.value) && cookie.value.value1
37-
)
38-
const cookieValue2 = computed(
39-
() => isObj(cookie.value) && cookie.value.value2
40-
)
41-
4233
return {
4334
cookie,
4435
getCookie,
4536
setCookie,
4637
removeCookie,
47-
cookieValue,
48-
cookieValue1,
49-
cookieValue2
38+
cookieValue
5039
}
5140
}
5241
})

src/helpers/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const checkType = (typeToCheck: any) =>
2+
Object.prototype.toString.call(typeToCheck)
3+
4+
export const isObj = (objToCheck: any) =>
5+
checkType(objToCheck) === '[object Object]'

0 commit comments

Comments
 (0)