我正在使用 tape用于在 JavaScript 中进行测试,但在某些情况下,我想设置一些配置变量,这些变量在一个文件中的所有测试中都可用。类似于 PhpUnit 中可用的 setUp 和 tearDown 方法。这些方法将分别在文件中的每个测试之前和之后执行。
例如:
test("setUp", function(t){
var person = {name: 'Jose', programmer: true};
});
test("Name isn't undefined", function(){
t.notEqual(person.name, undefined);
});
test("Is a programmer", function(t){
t.ok(person.programmer);
});
test("tearDown", function(){
//Do something else
});
最佳答案
回复有点晚了,但是是的。 通过 substack自己。
基本上,您只需将它简单地编写为另一个测试规范,但带有 setup
和 teardown
。
test('setup', function(t){
t.end();
});
test('teardown', function(t){
t.end();
});
关于javascript - 有没有办法在磁带上制作 setUp 和 tearDown 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31128728/