Sha*_*aja 3 javascript mocha.js
我已经使用 mocha 自动化了我的 api。结构就像 -
1.对于每个 api 有一个api_namex.js文件,其中 mocha 测试驻留
每个api_namex.js文件具有一个描述()和多它()内的描述()
现在,如果我在api_namex.js文件之一(比如 api_name1.js)中使用beforeEach(),那么在运行涉及运行所有 api_namex.js 文件的整个测试套件时,所有这些文件都会调用 beforeEach()。
我应该如何让它仅针对预期的 api_namex.js 文件运行? 之前也有同样的问题。
my_areas.js文件附在下面。我在这里使用了 beforeEach()。但是在运行整个测试套件时,这个 beforeEach 在每个测试用例之前都会被调用。我只希望在此 describe() 中的每个测试用例之前使用它。
var should = require('should'),
supertest = require('supertest'),
servicesGenerator = require('../../utils/services_generator_test.js'),
responseMsg = require('../../utils/response_messages.js'),
helper = require('../../utils/helper.js'),
testData = require('../../utils/test_data.js'),
apiEndPoints = require('../../utils/api_endpoints.js');
beforeEach(function (done) {
clearMyAreas();
done();
});
describe('My Areas', function () {
it('1: All Data Valid', function (done) {
servicesGenerator.postPlayoApi(apiEndPoints.myAreas)
.send(getValidMyAreasBody())
.end(function (err, res) {
baseValidator(err, res, 1, responseMsg.myAreasSuccess);
areasValidator(err, res, 1);
done();
});
});
it('2: Invalid userId', function (done) {
servicesGenerator.postPlayoApi(apiEndPoints.myAreas)
.send(getValidMyAreasBody(testData.userIdInvalid))
.end(function (err, res) {
baseValidator(err, res, 0, responseMsg.invalidUserId);
done();
});
});
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
436 次 |
最近记录: |