Skip to content

The docs should mention that a new instance of the class is created before each test #42

@jrumbinas

Description

@jrumbinas

Testdeck Version

0.0.6

Testdeck Package

  • @testdeck/core
  • @testdeck/mocha

NodeJS Version

  • 10

Mocha / Jasmine / Jest Version

  • Mocha: 6.1.4
  • @types/mocha: 5.2.6

Operating System

  • Mac OS X

Actual Behaviour

Consider the following test:

import { suite, test } from "@testdeck/mocha";

[{ title: 'world'}, { title: 'github'}]
.forEach(({title}) => {

    @suite(`Hello ${title}`)
    class Hello {
        constructor() {
            console.log('');
            console.log(`Hello ${title}`);
        }

        @test
        test1() {
            console.log('test1');
        }

        @test
        test2() {
            console.log('test2');
        }
    }
});

Hello class is instantiated 4 times, i.e. once per test

Hello world
test1
Hello world
test2
Hello github
test1
Hello github
test2

Expected Behaviour

Only 2 Hello class instances should have been created

Hello world
test1
test2
Hello github
test1
test2

Additional Information

Official documentation Instance Lifecycle Hooks is providing the impression that @suite class may have an internal state, which is clearly not true.

Please note, that suite scope state can only be achieved via class instance or actual mocha suite. IMHO it's a bad practice to pollute mocha suite context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions