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. vim插件之delimitMate.vim

    delimitMate.vim--这个插件主要是在插入模式下,用来自动补全括号.引号等 下载地址 http://www.vim.org/scripts/script.php?script_id=275 ...

  2. BZOJ1045: [HAOI2008]糖果传递&BZOJ1465: 糖果传递&BZOJ3293: [Cqoi2011]分金币

    [传送门:BZOJ1045&BZOJ1465&BZOJ3293] 简要题意: 给出n个数,每个数每次可以-1使得左边或者右边的数+1,代价为1,求出使得这n个数相等的最小代价 题解: ...

  3. css footer not displaying at the bottom of the page

    https://stackoverflow.com/questions/15960290/css-footer-not-displaying-at-the-bottom-of-the-page The ...

  4. 【实用篇】Android之应用程序实现自动更新功能

    我个人用的是友盟提供的自动更新组件,因此在这里只描述如何实用友盟提供的组件来完成程序的自动更新,步骤如下: 1.登录友盟官网,点击注册一个友盟账号. 2.注册成功后将会自动进入到添加新应用界面,选择添 ...

  5. 内联函数(Inline Functions)

    影响性能的一个重要因素是内联技巧.内联函数也可称为内嵌函数. 在C++中,函数调用需要建立栈环境,进行参数复制,保护调用现场,返回时,还要进行返回值复制,恢复调用现场.这些工作都是与完成特定任务的操作 ...

  6. Oracle数据库IP访问限制(IP白名单黑名单)

    1.编辑sqlnet.ora 内容为: #允许访问的IP(白名单) TCP.INVITED_NODES=(127.0.0.1,192.168.56.109,ip2,ip3,..,..本地IP..)若使 ...

  7. OpenSUSE42.3 leap 开启ssh登陆

    一.产看ssh是否安装 OpenSUSE:~ # rpm -qa | grep ssh libssh2-1-1.4.3-18.3.x86_64openssh-askpass-1.2.4.1-12.1. ...

  8. 如何更改AD域安全策略-密码必须符合复杂性要求

    通常我们在域系统-管理工具上面是找不到“域安全策略”的,我们只能找到“本地安全策略”,而更改“本地安全策略”是不会对域产生任何的作用的.下面这个步骤教你如何找到“域安全策略” 1.Start(开始)– ...

  9. 小米开源便签Notes-源码研究(1)-导出功能整体思路

    NotesListActivity是入口Activity. 响应菜单事件,我的手机是"左键菜单".如果菜单项的ID是"R.id.menu_export_text" ...

  10. [Python] Use Python Classes

    Object oriented classes work much like classes in other languages. Learn how to create them and use ...