[Unit Testing] Node testing: Test api Get request
2023-09-14 09:00:54 时间
Using mocha:
"devDependencies": { "should": "^5.2.0", "supertest": "^0.15.0" }
process.env.A127_ENV = 'test'; var should = require('should'); var request = require('supertest'); // uncomment this to get server to start automatically when test starts var server = require('../../../app'); // var target = '127.0.0.1:10010'; describe('Return translations with parameter fi via GET /languages?lang=fi', function() { it('should respond with an json object containing all the translations for given language', function(done) { request(server) .get('/languages?lang=fi') .set('Accept', 'application/json') .set('Content-Type', 'application/json') .set('Authorization', 'Bearer test_token') .expect(200) .end(function(err, res) { should.not.exist(err); should.exist(res.body.languageNames); should.exist(res.body.header); should.exist(res.body.masthead); should.exist(res.body.phoneCard); should.exist(res.body.recommendation); should.exist(res.body.footer); done(); }); }); });
describe('Try to get translations with parameter 8 via GET /languages?lang=8', function() { it('should respond with 404 and message language not found', function(done) { request(server) .get('/languages?lang=8') .set('Accept', 'application/json') .set('Content-Type', 'application/json') .set('Authorization', 'Bearer test_token') .expect(404) .end(function(err, res) { should.not.exist(err); should.exist(res.body.message); res.body.message.should.equal("language not found"); done(); }); }); });
describe('helps api test', function() { it('should return helps data when router is: GET: /api/helps', function(done) { request(server) .get('/api/helps') .set('Accept', 'application/json') .set('Content-Type', 'application/json') .set('Authorization', 'Bearer test_token') .expect(200) .end(function(err, res) { should.not.exist(err); should.exist(res.body.helpEntries); done(); }); }); });
相关文章
- 天气预报api免费接口_天气API
- Node.js 应用 peer dependency 的用法
- node多版本控制
- 使用 webpack 的 node api 学习 webpack
- Win10下从零搭建Linux+Ansible+K8S 学习环境笔记(1*Master/controller+3*Node)
- 译文:5个增强Node.js应用程序增强功能
- node与浏览器中的cookie
- Node.js中的关注点分离
- jsrsasign 前端 RSA 加密 node 端解密
- 使用express搭建第一个Web应用Node.js初学详解编程语言
- 使用Node操作MSSQL数据库(nodemssql)
- Linux内核API手册:实现技术最新突破(linux内核api手册)
- Linux环境下配置Node.js(linux配置node)
- Node.js与MySQL的卓越结合(nodemysql)
- Node.js使用初印象
- MySQL C API实现数据库应用程序(mysql的c语言api)
- Node.js连接MSSQL数据库的操作指南(node 链接mssql)
- 使用Node.js实现对MSSQL数据库的连接(node连接 mssql)
- Node MSSQL 报错处理 解决技巧分享(node mssql报错)
- 插入使用Node批量插入MSSQL数据库的实现(node mssql批量)
- 使用C语言搭建MySQL数据库API(c语言mysql api)
- MSSQL API调用:解放数据开发者(mssql的api调用)
- API实现MySQL数据库备份(api备份mysql)
- 深入解析Redis集群API的运用(redis集群的api)
- 利用Redis实现高效的Node限流(redis限流node)
- Redis读写分离API实现提升效率(redis读写分离api)
- 2014年最火的Node.JS后端框架推荐
- node.js中的定时器nextTick()和setImmediate()区别分析
- node.js中的fs.open方法使用说明
- node.js中的fs.createReadStream方法使用说明
- 浅析Node在构建超媒体API中的作用