gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 23:19:33 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com