Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
fetch
提交
9a04a066
F
fetch
项目概览
github
/
fetch
8 个月 前同步成功
通知
30
Star
25765
Fork
3216
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
fetch
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9a04a066
编写于
11月 14, 2016
作者:
M
Mislav Marohnić
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Share identical tests between Request & Response
上级
7f55e03b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
92 deletion
+51
-92
test/test.js
test/test.js
+51
-92
未找到文件。
test/test.js
浏览文件 @
9a04a066
...
@@ -101,6 +101,53 @@ exercise.forEach(function(exerciseMode) {
...
@@ -101,6 +101,53 @@ exercise.forEach(function(exerciseMode) {
var
nativeFirefox
=
/Firefox
\/
/
.
test
(
navigator
.
userAgent
)
&&
exerciseMode
===
'
native
'
var
nativeFirefox
=
/Firefox
\/
/
.
test
(
navigator
.
userAgent
)
&&
exerciseMode
===
'
native
'
var
polyfillFirefox
=
/Firefox
\/
/
.
test
(
navigator
.
userAgent
)
&&
exerciseMode
===
'
polyfill
'
var
polyfillFirefox
=
/Firefox
\/
/
.
test
(
navigator
.
userAgent
)
&&
exerciseMode
===
'
polyfill
'
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
function
testBodyExtract
(
factory
)
{
suite
(
'
body extract
'
,
function
()
{
featureDependent
(
suite
,
support
.
blob
,
'
type Blob
'
,
function
()
{
test
(
'
consume as blob
'
,
function
()
{
var
obj
=
factory
(
new
Blob
([
'
hello
'
]))
return
obj
.
blob
().
then
(
readBlobAsText
).
then
(
function
(
text
)
{
assert
.
equal
(
text
,
'
hello
'
)
})
})
test
(
'
consume as text
'
,
function
()
{
var
obj
=
factory
(
new
Blob
([
'
hello
'
]))
return
obj
.
text
().
then
(
function
(
text
)
{
assert
.
equal
(
text
,
'
hello
'
)
})
})
})
featureDependent
(
suite
,
support
.
arrayBuffer
,
'
type ArrayBuffer
'
,
function
()
{
test
(
'
consume as array buffer
'
,
function
()
{
var
original
=
arrayBufferFromText
(
'
name=hubot
'
)
return
factory
(
original
).
arrayBuffer
().
then
(
function
(
buf
)
{
assert
.
equal
(
readArrayBufferAsText
(
buf
),
readArrayBufferAsText
(
original
)
)
})
})
})
suite
(
'
type USVString
'
,
function
()
{
test
(
'
consume as text
'
,
function
()
{
return
factory
(
'
hello
'
).
text
().
then
(
function
(
text
)
{
assert
.
equal
(
text
,
'
hello
'
)
})
})
featureDependent
(
test
,
support
.
blob
,
'
consume as blob
'
,
function
()
{
return
factory
(
'
hello
'
).
blob
().
then
(
readBlobAsText
).
then
(
function
(
text
)
{
assert
.
equal
(
text
,
'
hello
'
)
})
})
})
})
}
// https://fetch.spec.whatwg.org/#headers-class
// https://fetch.spec.whatwg.org/#headers-class
suite
(
'
Headers
'
,
function
()
{
suite
(
'
Headers
'
,
function
()
{
test
(
'
constructor copies headers
'
,
function
()
{
test
(
'
constructor copies headers
'
,
function
()
{
...
@@ -430,52 +477,8 @@ suite('Request', function() {
...
@@ -430,52 +477,8 @@ suite('Request', function() {
})
})
})
})
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
testBodyExtract
(
function
(
body
)
{
suite
(
'
BodyInit extract
'
,
function
()
{
return
new
Request
(
''
,
{
method
:
'
POST
'
,
body
:
body
})
featureDependent
(
suite
,
support
.
blob
,
'
type Blob
'
,
function
()
{
test
(
'
consume as blob
'
,
function
()
{
var
request
=
new
Request
(
''
,
{
method
:
'
POST
'
,
body
:
new
Blob
([
'
hello
'
])})
return
request
.
blob
().
then
(
readBlobAsText
).
then
(
function
(
text
)
{
assert
.
equal
(
text
,
'
hello
'
)
})
})
test
(
'
consume as text
'
,
function
()
{
var
request
=
new
Request
(
''
,
{
method
:
'
POST
'
,
body
:
new
Blob
([
'
hello
'
])})
return
request
.
text
().
then
(
function
(
text
)
{
assert
.
equal
(
text
,
'
hello
'
)
})
})
})
featureDependent
(
suite
,
support
.
arrayBuffer
,
'
type ArrayBuffer
'
,
function
()
{
test
(
'
consume as array buffer
'
,
function
()
{
var
original
=
arrayBufferFromText
(
'
name=hubot
'
)
var
request
=
new
Request
(
''
,
{
method
:
'
POST
'
,
body
:
original
})
return
request
.
arrayBuffer
().
then
(
function
(
buf
)
{
assert
.
equal
(
readArrayBufferAsText
(
buf
),
readArrayBufferAsText
(
original
)
)
})
})
})
suite
(
'
type USVString
'
,
function
()
{
test
(
'
consume as text
'
,
function
()
{
var
request
=
new
Request
(
''
,
{
method
:
'
POST
'
,
body
:
'
hello
'
})
return
request
.
text
().
then
(
function
(
text
)
{
assert
.
equal
(
text
,
'
hello
'
)
})
})
featureDependent
(
test
,
support
.
blob
,
'
consume as blob
'
,
function
()
{
var
request
=
new
Request
(
''
,
{
method
:
'
POST
'
,
body
:
'
hello
'
})
return
request
.
blob
().
then
(
readBlobAsText
).
then
(
function
(
text
)
{
assert
.
equal
(
text
,
'
hello
'
)
})
})
})
})
})
})
})
...
@@ -488,52 +491,8 @@ suite('Response', function() {
...
@@ -488,52 +491,8 @@ suite('Response', function() {
assert
.
isTrue
(
res
.
ok
)
assert
.
isTrue
(
res
.
ok
)
})
})
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
testBodyExtract
(
function
(
body
)
{
suite
(
'
BodyInit extract
'
,
function
()
{
return
new
Response
(
body
)
featureDependent
(
suite
,
support
.
blob
,
'
type Blob
'
,
function
()
{
test
(
'
consume as blob
'
,
function
()
{
var
response
=
new
Response
(
new
Blob
([
'
hello
'
]))
return
response
.
blob
().
then
(
readBlobAsText
).
then
(
function
(
text
)
{
assert
.
equal
(
text
,
'
hello
'
)
})
})
test
(
'
consume as text
'
,
function
()
{
var
response
=
new
Response
(
new
Blob
([
'
hello
'
]))
return
response
.
text
().
then
(
function
(
text
)
{
assert
.
equal
(
text
,
'
hello
'
)
})
})
})
featureDependent
(
suite
,
support
.
arrayBuffer
,
'
type ArrayBuffer
'
,
function
()
{
test
(
'
consume as array buffer
'
,
function
()
{
var
original
=
arrayBufferFromText
(
'
name=Hubot
'
)
var
response
=
new
Response
(
original
)
return
response
.
arrayBuffer
().
then
(
function
(
buf
)
{
assert
.
equal
(
readArrayBufferAsText
(
buf
),
readArrayBufferAsText
(
original
)
)
})
})
})
suite
(
'
type USVString
'
,
function
()
{
test
(
'
consume as text
'
,
function
()
{
var
response
=
new
Response
(
'
hello
'
)
return
response
.
text
().
then
(
function
(
text
)
{
assert
.
equal
(
text
,
'
hello
'
)
})
})
featureDependent
(
test
,
support
.
blob
,
'
consume as blob
'
,
function
()
{
var
response
=
new
Response
(
'
hello
'
)
return
response
.
blob
().
then
(
readBlobAsText
).
then
(
function
(
text
)
{
assert
.
equal
(
text
,
'
hello
'
)
})
})
})
})
})
test
(
'
creates Headers object from raw headers
'
,
function
()
{
test
(
'
creates Headers object from raw headers
'
,
function
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录