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. dropify,不错的图片上传预览插件

    引言 传统的图片上传,很丑.点击选择之后,还无法预览. 有一种方案是传到服务器,然后返回地址,然后显示,比较麻烦. 用这个dropify,就可以解决之歌问题. 看效果 用法 1.引入文件,需要jque ...

  2. orm 通用方法——DeleteModel 主键删除

    定义代码: /** * 描述:删除对象 * 作者:Tianqi * 日期:2014-09-17 * param:model 对象实例,包含主键 * return:int 受影响行数 * return: ...

  3. c# 引用ConfigurationManager 类

    c#添加了Configuration;后,竟然找不到 ConfigurationManager 这个类,后来才发现:虽然引用了using System.Configuration;这个包,但是还是不行 ...

  4. excel导入数据的

    .aspx 文件 <form id="form1" runat="server"> <div> <asp:FileUpload I ...

  5. 学习推荐《Python神经网络编程》中文版PDF+英文版PDF+源代码

    推荐非常适合入门神经网络编程的一本书<Python神经网络编程>,主要是三部分: 介绍神经网络的基本原理和知识:用Python写一个神经网络训练识别手写数字:对识别手写数字的程序的一些优化 ...

  6. CMDB学习之七-实现采集错误捕捉,日志信息处理

    首先采集disk的具体实现方上代码: # !/usr/bin/env python # -*- coding:utf-8 -*- from .base import BasePlugin import ...

  7. Json学习总结(1)——Java和JavaScript中使用Json方法大全

    摘要:JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使用了类似于C语 ...

  8. HRBUST 1819 石子合并问题--圆形版

    石子合并问题--圆形版 Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HRBUST. Original ...

  9. 【iOS开发-27】解决方式:An error was encountered while running(Domain=FBSOpenApplicationErrorDomain, Code=4)

    iOS simulator出现故障,提示: An error was encountered while running (Domain = FBSOpenApplicationErrorDomain ...

  10. 什么是string interning(字符串驻留)以及python中字符串的intern机制

    Incomputer science, string interning is a method of storing only onecopy of each distinct string val ...