Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gzupanda
code-server
提交
3cebfcd4
C
code-server
项目概览
gzupanda
/
code-server
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
code-server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
3cebfcd4
编写于
2月 03, 2021
作者:
J
Joe Previte
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add tests for logError
上级
71cf459e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
50 addition
and
2 deletion
+50
-2
test/util.test.ts
test/util.test.ts
+50
-2
未找到文件。
test/util.test.ts
浏览文件 @
3cebfcd4
import
{
logger
as
l
}
from
"
@coder/logger
"
// Note: we need to import logger from the root
import
{
arrayify
,
getFirstString
,
normalize
,
plural
,
resolveBase
,
split
,
trimSlashes
}
from
"
../src/common/util
"
// because this is the logger used in logError in ../src/common/util
import
{
logger
}
from
"
../node_modules/@coder/logger
"
import
{
arrayify
,
getFirstString
,
logError
,
normalize
,
plural
,
resolveBase
,
split
,
trimSlashes
,
}
from
"
../src/common/util
"
type
LocationLike
=
Pick
<
Location
,
"
pathname
"
|
"
origin
"
>
type
LocationLike
=
Pick
<
Location
,
"
pathname
"
|
"
origin
"
>
...
@@ -96,6 +107,7 @@ describe("util", () => {
...
@@ -96,6 +107,7 @@ describe("util", () => {
it
(
"
should return value it's already an array
"
,
()
=>
{
it
(
"
should return value it's already an array
"
,
()
=>
{
expect
(
arrayify
([
"
hello
"
,
"
world
"
])).
toStrictEqual
([
"
hello
"
,
"
world
"
])
expect
(
arrayify
([
"
hello
"
,
"
world
"
])).
toStrictEqual
([
"
hello
"
,
"
world
"
])
})
})
it
(
"
should wrap the value in an array if not an array
"
,
()
=>
{
it
(
"
should wrap the value in an array if not an array
"
,
()
=>
{
expect
(
expect
(
arrayify
({
arrayify
({
...
@@ -104,6 +116,7 @@ describe("util", () => {
...
@@ -104,6 +116,7 @@ describe("util", () => {
}),
}),
).
toStrictEqual
([{
name
:
"
Coder
"
,
version
:
"
3.8
"
}])
).
toStrictEqual
([{
name
:
"
Coder
"
,
version
:
"
3.8
"
}])
})
})
it
(
"
should return an empty array if the value is undefined
"
,
()
=>
{
it
(
"
should return an empty array if the value is undefined
"
,
()
=>
{
expect
(
arrayify
(
undefined
)).
toStrictEqual
([])
expect
(
arrayify
(
undefined
)).
toStrictEqual
([])
})
})
...
@@ -113,11 +126,46 @@ describe("util", () => {
...
@@ -113,11 +126,46 @@ describe("util", () => {
it
(
"
should return the string if passed a string
"
,
()
=>
{
it
(
"
should return the string if passed a string
"
,
()
=>
{
expect
(
getFirstString
(
"
Hello world!
"
)).
toBe
(
"
Hello world!
"
)
expect
(
getFirstString
(
"
Hello world!
"
)).
toBe
(
"
Hello world!
"
)
})
})
it
(
"
should get the first string from an array
"
,
()
=>
{
it
(
"
should get the first string from an array
"
,
()
=>
{
expect
(
getFirstString
([
"
Hello
"
,
"
World
"
])).
toBe
(
"
Hello
"
)
expect
(
getFirstString
([
"
Hello
"
,
"
World
"
])).
toBe
(
"
Hello
"
)
})
})
it
(
"
should return undefined if the value isn't an array or a string
"
,
()
=>
{
it
(
"
should return undefined if the value isn't an array or a string
"
,
()
=>
{
expect
(
getFirstString
({
name
:
"
Coder
"
})).
toBe
(
undefined
)
expect
(
getFirstString
({
name
:
"
Coder
"
})).
toBe
(
undefined
)
})
})
})
})
describe
(
"
logError
"
,
()
=>
{
let
spy
:
jest
.
SpyInstance
beforeEach
(()
=>
{
spy
=
jest
.
spyOn
(
logger
,
"
error
"
)
})
afterEach
(()
=>
{
jest
.
clearAllMocks
()
})
afterAll
(()
=>
{
jest
.
restoreAllMocks
()
})
it
(
"
should log an error with the message and stack trace
"
,
()
=>
{
const
message
=
"
You don't have access to that folder.
"
const
error
=
new
Error
(
message
)
logError
(
"
ui
"
,
error
)
expect
(
spy
).
toHaveBeenCalled
()
expect
(
spy
).
toHaveBeenCalledWith
(
`ui:
${
error
.
message
}
${
error
.
stack
}
`
)
})
it
(
"
should log an error, even if not an instance of error
"
,
()
=>
{
logError
(
"
api
"
,
"
oh no
"
)
expect
(
spy
).
toHaveBeenCalled
()
expect
(
spy
).
toHaveBeenCalledWith
(
"
api: oh no
"
)
})
})
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录