Search code examples
javascriptunit-testingtestingtapnode.js-tape

Is there a way to make a setUp and tearDown methods on tape?


I am using tape for testing in JavaScript, but in some cases I want to set some configuration variables that are available in all the tests within a file. Something like the setUp and tearDown methods available in PhpUnit. Those methods will be executed before and after every test in the file, respectively.

e.g:

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
});

Solution

  • A little too late for the reply but yes there is. By substack himself.

    Basically you just write it simply as another test spec but with setup and teardown.

    test('setup', function(t){
    t.end();
    });
    test('teardown', function(t){
    t.end();
    });