在 Jasmine for Angular

问题描述

我一直在使用 Jasmine、Karma 为 Angular 8 应用编写测试。我运行 ng 测试并在我的 Chrome 浏览器中的 localhost:9876 中查看结果。到目前为止,我一直在为组件功能的文档字符串使用 describe 函数,然后在该描述中,我有许多描述实际测试的函数。 我们已经开始转向 Cucumber 来描述组件的功能。有什么方法可以在浏览器中生成测试报告以查看它们在 Cucumber 规范中的表现吗? 例如,以这个 Cucumber 示例规范为例:

Feature: Guess the word

# The first example has two steps
Scenario: Maker starts a game
    When the Maker starts a game
    Then the Maker waits for a Breaker to join

# The second example has three steps
Scenario: Breaker joins a game
    Given the Maker has started a game with the word "silky"
    When the Breaker joins the Maker's game
    Then the Breaker must guess a word with 5 characters

如果我将其转换为茉莉花测试:

describe('Feature: Guess the word',() => {
    describe('Scenario: Maker starts a game',() => {
        it('When the Maker starts a game,Then the Maker waits for a Breaker to join',() => {
            // Test code
        });
    });

    describe('Scenario: Breaker joins a game',() => {
        it('Given the Maker has started a game with the word "silky",When the Breaker joins the Maker's game,Then the Breaker must guess a word with 5 characters',() => {
            // Test code
        });
    });
});

导致测试在一个不容易阅读的长行中。如果我将它们分解成单独的描述块,它会分解它们,但格式仍然缩进,但与 Cucumber 规范不同。

describe('Scenario: Breaker joins a game',() => {
    describe('Given the Maker has started a game with the word "silky"',() => {
        describe('When the Breaker joins the Maker's game',() => {
            it('Then the Breaker must guess a word with 5 characters',() => {
                // Test code
            });
        });
    });
});

此外,仅将描述块用于格式化似乎并不理想。是否有可能在 it() 函数文本中插入 HTML 以生成带有空格、标签、列表 (li) 元素等的格式化测试报告?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)