Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 如何对yeoman发电机进行单元测试_Unit Testing_Yeoman - Fatal编程技术网

Unit testing 如何对yeoman发电机进行单元测试

Unit testing 如何对yeoman发电机进行单元测试,unit-testing,yeoman,Unit Testing,Yeoman,我看了官方的指南 但这让我有点困惑。 helpers.run返回我可以调用方法等的运行上下文。 但我不知道如何测试文件是否存在(使用assert.file) 我的印象是,helpers.run将在内存或文件系统中创建文件。但是,assert.file总是失败。 在运行测试之前,文件系统上存在的文件不会失败 当我运行我的生成器(yo my generator)时,我看到文件已创建 如何测试文件是否已创建? 这是到目前为止我的代码,它不起作用 我用茉莉花做测试 let helpers = requi

我看了官方的指南 但这让我有点困惑。
helpers.run
返回我可以调用方法等的运行上下文。 但我不知道如何测试文件是否存在(使用
assert.file
) 我的印象是,
helpers.run
将在内存或文件系统中创建文件。但是,
assert.file
总是失败。 在运行测试之前,文件系统上存在的文件不会失败

当我运行我的生成器(yo my generator)时,我看到文件已创建

如何测试文件是否已创建? 这是到目前为止我的代码,它不起作用

我用茉莉花做测试

let helpers = require('yeoman-test');
let assert = require('yeoman-assert');

describe('generator:test', function () {

    let path = require('path');

    beforeEach(function () {
        console.log(path.join(__dirname, '../generators/app'));
        // The object returned acts like a promise, so return it to wait until the process is done
        helpers.run(path.join(__dirname, '../generators/app'))
            .withPrompts({
                name: 'test',
                appName: 'test',
                appTitle: 'test',
                apiEndpoint: 'http://localhost'
            });
    })

    it('all config files', function () {

        assert.file(#arrayOfFiles#);
    });
});

我知道这是一个老生常谈的问题,但由于它在谷歌测试Yeoman生成器的搜索结果中排名很高,所以尝试回答它似乎很有用:

您的beforeAll需要返回helpers.run返回的承诺。否则,测试运行程序将不会在运行实际测试之前等待足够长的时间,并且文件将不在那里。因此,您的示例应该如下所示:

let helpers = require('yeoman-test');
let assert = require('yeoman-assert');

describe('generator:test', function () {

    let path = require('path');

    beforeEach(function () {
        return helpers.run(path.join(__dirname, '../generators/app'))
            .withPrompts({
                name: 'test',
                appName: 'test',
                appTitle: 'test',
                apiEndpoint: 'http://localhost'
            });
    })

    it('all config files', function () {
        assert.file(#arrayOfFiles#);
    });
});

很抱歉,我没有接受你的答案,但我很久以前就放弃了这个项目,无法测试你的代码是否有效。如果有人能证实这一点,我将欣然接受你的回答