微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Jasmine for Angular

如何解决在 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 举报,一经查实,本站将立刻删除。