For intergration tests, always remember when you create a 'mass' you should aslo clean up the 'mass'.

For example when you start the server, you need to close the server after the tests. See the post: http://www.cnblogs.com/Answer1215/p/7554662.html

Also for authentication, when you create a new user for testing, you should also clean it up.

There is a help function for tests, to create a new user:

async function createNewUser(overrides) {
const password = faker.internet.password()
const userData = generateUserData(overrides)
const {email, username} = userData
const user = await api
.post('users', {user: {email, password, username}})
.then(getUser)
return {
user,
cleanup() {
return api.delete(`users/${user.username}`)
},
}
}

In the return value, it also provide a function to clean up the user.

const api = axios.create({
baseURL: 'http://localhost:3000/api',
}) describe('authenticated', () => {
let cleanupUser
beforeAll(async () => {
const results = await createNewUser()
cleanupUser = results.cleanup
api.defaults.headers.common.authorization = `Token ${results.user.token}` // set default http header, add authorization for JWT token
}) afterAll(async () => {
await cleanupUser()
api.defaults.headers.common.authorization = ''
}) })

[Node & Tests] Intergration tests for Authentication的更多相关文章

  1. [Node & Testing] Intergration Testing with Node Express

    We have express app: import _ from 'lodash' import faker from 'faker' import express from 'express' ...

  2. How to: Run Tests from Microsoft Visual Studio

    https://msdn.microsoft.com/en-us/library/ms182470.aspx Running Automated Tests in Visual Studio Visu ...

  3. C# Note37: Writing unit tests with use of mocking

    前言 What's mocking and its benefits Mocking is an integral part of unit testing. Although you can run ...

  4. Tests for normality正态分布检验

    欢迎关注博主主页,学习python视频资源,还有大量免费python经典文章 sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频教程) https://study.163.com/course/ ...

  5. 自动化运维工具Ansible之Tests测验详解

    Ansible Tests 详解与使用案例 主机规划 添加用户账号 说明: 1. 运维人员使用的登录账号: 2. 所有的业务都放在 /app/ 下「yun用户的家目录」,避免业务数据乱放: 3. 该用 ...

  6. crtmpserver实现防盗流和流推送验证

    Protecting your streams from webpage copy&paste flash code, listing or recording 保护流,防止在页面上被复制&a ...

  7. crtmpserver实现防盗流和流推送验证 之二

    IV. Catching the thieves 抓住小偷 Well, we have just added a secure mechanism to our little streaming se ...

  8. OPENVPN2.3配置文档官方说明

    openvpn Section: Maintenance Commands (8)Index NAME openvpn - secure IP tunnel daemon. SYNOPSIS open ...

  9. hbase官方文档(转)

    FROM:http://www.just4e.com/hbase.html Apache HBase™ 参考指南  HBase 官方文档中文版 Copyright © 2012 Apache Soft ...

随机推荐

  1. hdoj--5053--the Sum of Cube(水)

    the Sum of Cube Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tot ...

  2. javascript 提交弹窗

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. HDU 4359 Easy Tree DP? 组合数学+动归

    题意:定义一种树,每个节点的权值都是20到2n-1,每个权值出现一次,每个节点的左子树的权值和小于右子树,除非只有一个子树.给你n和d,问有n个节点且恰好深度是d的这种树有多少种. 比赛的时候我没有做 ...

  4. 总结C#保留小数位数

    2.C#保留小数位N位,四舍五入 . decimal d= decimal.Round(decimal.Parse("0.55555"),2); 3.C#保留小数位N位四舍五入 M ...

  5. 转:Java读写文件各种方法及性能比较

    干Java这么久,一直在做WEB相关的项目,一些基础类差不多都已经忘记.经常想得捡起,但总是因为一些原因,不能如愿. 其实不是没有时间,只是有些时候疲于总结,今得空,下定决心将丢掉的都给捡起来. 文件 ...

  6. c#时间差高精度检查

    两个时间差的高精度检查 static void Main(string[] args) { Console.WriteLine("开始时间:" + DateTime.Now.ToS ...

  7. CSUOJ 1555 Inversion Sequence

    1555: Inversion Sequence Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: 107  Solved: 34 Description ...

  8. snmpd修改端口

    http://blog.csdn.net/cau99/article/details/5077239 http://blog.csdn.net/gua___gua/article/details/48 ...

  9. Peer To Peer——对等网络

    今年的考试.大问题没怎么出现. 就是考英语第二天的下午,发生网络阻塞的现象,不影响大局.可是事出有因,我们还是须要看看是什么影响到了考生抽题.最后查了一圈,发现其它几场的英语考试听力都是19M大小,而 ...

  10. 漫漫人生路-学点Jakarta基础-Java8新特性 Stream/Lambda

    背景 Stream 是对集合(Collection)对象功能的增强,它专注于对集合对象进行各种非常便利.高效的聚合操作(aggregate operation),或者大批量数据操作 (bulk dat ...