javascript - Jasmine Angular Testing - 是否可以在描述方法上添加属性?

标签 javascript angular unit-testing jasmine

我是 jasmine 测试的新手,来自 xUnit .Net 背景。

是否有可能以这种方式标记一个测试或一组测试:

[SomeAttribute]

 describe("A suite", function() {
   it("contains spec with an expectation", function() {
           expect(true).toBe(true);   
             });
 });

jasmine是否支持any sort of attributes or identifiers ?我的目标实际上是运行一组描述测试两次,在测试运行之间使用不同的设置。我不想重复测试。一个测试是否有可能启动其他测试?

这个问题是假设我对复制一个构建步骤来运行测试服两次感到满意,第二次运行只是测试的一个子集。

编辑:我希望如何消费它的更现实的例子

[Theory]
[TestData(true)]
[TestData(false)]
 describe("A suite", function() {

    beforeEach(() => {
     configureTestBed(/*someHow get input*/);
    });

   it("contains spec with an expectation", function() {
           expect(true).toBe(true);   
             });
 });

最佳答案

您可以做的是定义单独的函数,这些函数将接受来自您代码中其他地方的参数。

像这样的事情会做:

describe('Sample describe', () => {
    testFunction(1);
});

function testFunction(param1) {
    it('should execute test with params', () => {
        console.log(param1);
        expect(param1).toBe(1);
    });
}

关于javascript - Jasmine Angular Testing - 是否可以在描述方法上添加属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51237478/

相关文章:

javascript - 使 'dropdown-content' 与 paper-dropdown-menu 的宽度相同?

javascript - 在后台上下文中的脚本之间进行通信(后台脚本,浏览器操作,页面操作,选项页面等)

javascript - Titanium:使用 Titanium UI 设置文本字段的 ID

angular - 在 Ionic 2 中从一个组件到另一个组件的动画过渡

c# - 简单 `Assert.IsAssignableFrom<T>` 失败

unit-testing - Cakephp 3 - 单元测试验证默认

java - 查找被忽略的 junits 的程序

javascript - 如何为 requireJs 使用 Assetic

angular - 从 Angular 8 的下拉列表中删除/禁用选定的选项(动态创建的)

angular - ngrx 错误 : Actions must have a type property