- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 mocha-chai
上编写了以下测试用例,它运行良好并显示所有结果都成功通过。但它不会在成功通过所有 6 个测试用例后终止执行。我不知道是什么原因导致我的测试用例没有自动终止,我需要按CTRL+C来终止测试用例。
我不知道是什么原因测试已经成功通过但没有终止。我也在测试用例的末尾写了 done() 但它仍然不起作用
我使用 PostgreSQL 作为数据库,使用 NodeJS 作为后端服务器。
test.js
const { colors } = require('mocha/lib/reporters/base');
colors.pass = 32;
const { describe, it } = require('mocha');
const { expect } = require('chai');
const request = require('superagent');
const should = require('should');
const fs = require('fs');
const path = require('path');
const moment = require('moment-timezone');
const envPath = path.join(__dirname, '.env');
require('dotenv').config({ path: envPath });
const Sequelize = require('sequelize');
const db = require('../db/models');
// Test that server is running or not
describe('Unit tests for add user', () => {
// Gateway api test case and it's works fine
});
// Read the test cases stored from database and stored in an array
describe('Test Cases', () => {
// Read the test cases from database
});
// Test case to write test data in csv and upload the csv and insert user information in csv
describe('Process data user csv', () => {
it('create user csv to write data in csv', done => {
// Create user csv from test data and it's passed and successfully completed it
});
it('Upload user csv and insert the user in the database with accurate data', done => {
// Upload user csv and insert user information from csv and it's passed and successfully completed it
});
it('verify user information from user table', done => {
// This method verifies the user data stored user table, which has inserted in test case.
// Sequlieze query which fetch the user information
TestService.executeQuery(
dbQuery.qGetUserDetails,
{
email: arrTestCases[0].expected_result.email,
},
'select'
)
.then(data => {
should(data[0].email).equal(arrTestCases[0].expected_result.email);
done();
});
});
});
});
app.query.js
/**
* @description default queries
*/
module.exports = {
qGetUserDetails: `select * from "Users" where email = :email and is_active = true and is_deleted = false`,
};
Test.service.js
/**
* @class TestService
*/
const Sequelize = require('sequelize');
const db = require('../db/models');
module.exports = class TestService {
/**
* @static execute query
* @param {*} query
* @param {*} replacements
* @param {*} operation
* @memberof TestService
*/
static executeQuery(query, replacements, operation) {
return new Promise((resolve, reject) => {
let queryType;
if (operation === 'insert') {
queryType = Sequelize.QueryTypes.INSERT;
} else if (operation === 'update') {
queryType = Sequelize.QueryTypes.UPDATE;
} else if (operation === 'select') {
queryType = Sequelize.QueryTypes.SELECT;
} else if (operation === 'delete') {
queryType = Sequelize.QueryTypes.DELETE;
} else {
queryType = Sequelize.QueryTypes.SELECT;
}
return db.sequelize
.query(query, { replacements, type: queryType, raw: true })
.then(data => resolve(data))
.catch(err => reject(err));
});
}
};
最佳答案
I don't know what is the reason test has been successfully passed but does not terminate.
当所有测试都运行后,您并没有关闭数据库句柄,这意味着 Node.js 不知道您已经完成。
你可以添加一个根级别的 after
钩子(Hook)来关闭它:
after(() => {
sequelize.close();
});
关于javascript - mocha chai 测试用例不会自动终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53866577/
我正在使用 mocha 和 chai 进行 TDD 以测试一些 NodeJS 脚本,每次我想再次运行测试时都必须运行“mocha”。 有没有办法设置 mocha 和 chai 在我保存源文件后立即运行
如果任何测试失败,我正在尝试配置 mocha 以重试整个套件。 我导航到一个 URL,然后填充一个表单并提交,然后用户被重定向,如果找到某个元素,则最后一次测试通过。 如果找不到该元素,我需要再次导航
我想知道是否有办法让 mocha 列出它将执行的所有测试。当我使用 mocha --help 列出它们时,我没有看到任何合理的选项;有几个报告者,但似乎没有一个旨在列出将要处理的文件(或命名将要运行的
before()、after()、beforeEach()、afterEach() 等 mocha Hook 无法正常工作。 only 方法也不起作用。 beforeEach 都没有被调用。我得到一个
我已经看到很多关于此的问题,但所有修复都不适用于我的代码。 我做错了什么?我的 beforeEach 没有被执行。 这是单元测试代码: var assert = require('assert');
如何在 mocha 测试之间共享资源(例如连接)? cookies.test.js: describe('Cookies', function() { it('setCookie()', func
我正在尝试以编程方式运行 mocha。 runner的代码如下: var Mocha = require("mocha"); var mocha = new Mocha(); mocha.report
我正在遵循此 tutorial 的第 1 步 我有以下文件夹结构: ├── lib │ ├── json │ │ ├── messages.json │ │ └── testMessages.json
我希望能够扩展 mocha 测试结果并从可用的 mocha 对象中收听它们。首先,我正在寻找“通过”结果。 看起来他们可能是从套件中订阅的,但我不确定如何...... 我尝试了以下我认为会听到我所有测
我正在运行此测试(简化),该测试按预期失败了……但是,尽管失败了,但它仍要等待20秒的全部超时时间。如何使它立即失败? it("should fail before timeout", functio
我是Java语言世界的新手,主要涉足OOP。我试图在网上查找Karma和 Mocha 之间的明显区别,但徒劳无功。我知道Karma是一个测试运行器,而Mocha是一个单元测试框架,但是Mocha也有自
我有一段代码,其中某些测试在 CI 环境中总是会失败。我想根据环境条件禁用它们。 如何在运行时执行期间以编程方式跳过 mocha 中的测试? 最佳答案 您可以通过在describe或it block
我想使用 chai 应该断言检查我的响应对象是否包含提到的属性。 下面是我的代码片段: chai.request(app) .post('/api/signup') .
例如,默认情况下,背景颜色为绿色或红色。我想将绿色/红色作为前景,将背景作为我的默认颜色(白色)。 因为在浅色终端配色方案上很难看到任何东西,因为前景是黑色的,而背景会变成红色或绿色。 最佳答案 在
有没有办法在 mocha 记者中获取当前测试的文件名? 我在基础和示例中找不到任何内容。 最佳答案 实际上,文件名在 中传递给了 Suite文件 Mocha 中的字段从 this 开始拉取请求。只是现
在我走向 TDD 的过程中,我使用了 Mocha、chai 和 sinon。 那里肯定有一个学习曲线。 我的目标是编写一个测试来验证 method4 是否已执行。我如何做到这一点? //MyData.
我正在使用mocha和chai作为断言。 我在规范中有几个主张: Exp1.should.be.true Exp2.should.be.true Exp3.should.be.true 如果其中之一失
根据 Mocha 文档,“Mocha 测试串行运行”这意味着按照它们的定义顺序。 我的问题是:是什么让 异步 (带有完成回调)测试不同于 同步 ? 最佳答案 您通过传递给 it 来告诉 Mocha 测
我正在尝试将 mocha 绑定(bind)写入 PureScript 并且对 Control.Monad.Eff 完全感到困惑 describe(function(){ //do stuff }
我对 mocha 框架有点陌生。此代码应该抛出异常,但不会。 (为简单起见,将所有代码放入测试中) describe("Test", function() { it("this should
我是一名优秀的程序员,十分优秀!