当我使用命令行运行测试时,所有测试都通过了
describe('my tests', function () {
context('test a specific thing', function () {
it('should store a data into the database', function() {
// store data here and test that it's successful
});
it('should fetch that data we stored earlier', function() {
// fetch that data and test that it's successful
});
});
});
但是当我使用Mocha Sidebar extension运行Visual Studio Code的(运行所有测试)时,它说没有存储任何数据
...
it('should fetch that data we stored earlier', function() {
// fails to fetch and it returns 0 row of data
});
...
这让我开始思考构建考试的方式。看到插件在Run Suite | Debug Suite
,Debug Item | Run Item
和describe()
的上方分别显示context()
和it()
时,我认为它们应该分别可调试和可运行。
我是否应该通过一系列it()
保留数据?
describe('my tests', function () {
context('test a specific thing', function () {
it('should store a data into the database', function() {
// store data here and test that it's successful
});
context('since storing worked, only test fetching here', function() {
before('store data', function () {
// expect storing to work now
});
it('should fetch that data we just stored', function() {
// fetch that data and test that it's successful
});
})
});
});