Build Mocha test dynamically after getting data from webdriver.io

后端 未结 3 1255
南旧
南旧 2021-01-19 09:32

I\'m looking for a solution to define Mocha tests after getting data asynchronously.

For now, I use gulp-webdriver to getting HTML content with Selenium. And I wan

3条回答
  •  醉梦人生
    2021-01-19 10:05

    You can actually create dynamic It() tests with mocha if you don't mind abusing the before() hook a bit:

    before(function () {
        console.log('Let the abuse begin...');
        return promiseFn().
            then(function (testSuite) {
                describe('here are some dynamic It() tests', function () {
                    testSuite.specs.forEach(function (spec) {
                        it(spec.description, function () {
                            var actualResult = runMyTest(spec);
                            assert.equal(actualResult, spec.expectedResult);
                        });
                    });
                });
            });
    });
    
    it('This is a required placeholder to allow before() to work', function () {
        console.log('Mocha should not require this hack IMHO');
    });
    

提交回复
热议问题