admin管理员组文章数量:1321819
Both JUnit and N/XUnit enable us to parameterize tests which differ only by input values and expected results. In other words, we can statically define sets of test data (inputs + expected results) and let one single test execute and validate results for each of the input sets. We can do the same in JS using at least two utilities.
However, for Java and .Net we can generalize tests even more and instead of testing for specific values we can describe the rules for generating input data and generate test data on the fly, using theories ("@Theory" and "[Theory]" respectively).
What utility is there in JS that enables this level of abstraction in writing tests?
Both JUnit and N/XUnit enable us to parameterize tests which differ only by input values and expected results. In other words, we can statically define sets of test data (inputs + expected results) and let one single test execute and validate results for each of the input sets. We can do the same in JS using at least two utilities.
However, for Java and .Net we can generalize tests even more and instead of testing for specific values we can describe the rules for generating input data and generate test data on the fly, using theories ("@Theory" and "[Theory]" respectively).
What utility is there in JS that enables this level of abstraction in writing tests?
Share Improve this question asked Oct 19, 2018 at 1:29 krazyk4tladykrazyk4tlady 4291 gold badge6 silver badges15 bronze badges 1- 1 Use async.each in javascript for parameterized tests <caolan.github.io/async/docs.html#each> – Mridula Commented Nov 26, 2018 at 23:56
1 Answer
Reset to default 11I wanted to do something similar and just solved it by creating an array with the input/output parameters and calling that in a loop. This is just a basic example, but I might keep working on it a little more to see what I can make it do.
describe('Arrow', () => {
const theories = [
[undefined, "left-arrow", "<"],
["left", "left-arrow", "<"],
["right", "right-arrow", ">"]
];
theories.forEach(([dir, className, arrow]) => {
it(`should render the correct arrow given ${dir} direction`, () => {
const wrapper = shallow(<Arrow dir={dir} onClick={jest.fn()} />);
expect(wrapper.hasClass(className)).toEqual(true);
expect(wrapper.text().toEqual(arrow);
});
});
本文标签: javascriptDoes Mocha offer the option to parameterize tests quotTheoryquot styleStack Overflow
版权声明:本文标题:javascript - Does Mocha offer the option to parameterize tests "@Theory" style? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742106873a2421058.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论