Toggle navigation
Toggle navigation
This project
Loading...
Sign in
test
/
demo-chai-http
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
lintry
2016-10-25 09:55:23 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c1bade76a9d8c3bec3142d379a240ecdf28fd5cf
c1bade76
0 parents
测试模块样例
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
0 deletions
package.json
readme.md
test_template_by_chai-http.js
package.json
0 → 100644
View file @
c1bade7
{
"name"
:
"demo-chai-http"
,
"version"
:
"1.0.0"
,
"description"
:
""
,
"main"
:
"test_template_by_chai-http.js"
,
"scripts"
:
{
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
"repository"
:
{
"type"
:
"git"
,
"url"
:
"git@gitlab.kmlab.com:test/demo-chai-http.git"
},
"keywords"
:
[],
"author"
:
"lintry <shenlin00@gmail.com>"
,
"license"
:
"MIT"
,
"dependencies"
:
{
"chai"
:
"^3.5.0"
,
"chai-http"
:
"^3.0.0"
,
"should"
:
"^11.1.1"
}
}
readme.md
0 → 100644
View file @
c1bade7
##使用chai-http的远程接口测试用例DEMO
### 安装运行
```
sh
npm install
mocha test_template_by_chai-http.js
```
### 相关参考资料
-
[
mocha
](
https://github.com/mochajs/mocha
)
-
[
chai
](
https://github.com/chaijs/chai
)
-
[
chai-http
](
https://github.com/chaijs/chai-http
)
-
[
should API
](
http://shouldjs.github.io/
)
-
[
Mocha和Should、Supertest模块搭建Node.js单元测试环境
](
http://itbilu.com/nodejs/npm/VyrFOe51-.html
)
-
[
测试用例:mocha,should,istanbul
](
http://wiki.jikexueyuan.com/project/node-lessons/mocha-should-istanbul.html
)
test_template_by_chai-http.js
0 → 100644
View file @
c1bade7
describe
(
'测试模块'
,
function
()
{
var
chai
=
require
(
'chai'
),
should
=
require
(
'should'
),
chaiHttp
=
require
(
'chai-http'
);
chai
.
use
(
chaiHttp
);
var
agent
=
chai
.
request
.
agent
(
'http://onwall.cn'
);
it
(
'测试接口'
,
function
(
done
)
{
// this.timeout(5000);
agent
.
post
(
'/domino/b/auth_syslogin.do'
)
.
send
({
user_code
:
'IT001001DZ'
,
user_password
:
'8ddcff3a80f4189ca1c9d4d902c3c909'
})
.
end
(
function
(
err
,
res
)
{
// 登录应该成功
try
{
var
result
=
JSON
.
parse
(
res
.
text
);
}
catch
(
e
)
{
console
.
error
(
e
);
should
.
not
.
exist
(
e
);
}
res
.
status
.
should
.
equal
(
200
);
result
.
ret
.
should
.
equal
(
'OK'
);
return
agent
.
get
(
'/domino/b/order_query.do'
)
.
end
(
function
(
err
,
res
)
{
//返回值状态应该200且有OK
try
{
var
result
=
JSON
.
parse
(
res
.
text
);
}
catch
(
e
)
{
console
.
error
(
e
);
should
.
not
.
exist
(
e
);
}
res
.
status
.
should
.
equal
(
200
);
result
.
ret
.
should
.
equal
(
'OK'
);
//判断返回数据是否存在指定的属性或数值是否正确
let
content
=
result
.
content
;
content
.
should
.
have
.
property
(
'order_status_map'
);
content
.
should
.
have
.
property
(
'order_list'
);
content
.
order_list
.
length
.
should
.
aboveOrEqual
(
0
);
done
();
}
);
});
})
});
Please
register
or
login
to post a comment