您可以连接多个茉莉匹配器吗?

发布于 2025-01-21 09:24:24 字数 749 浏览 1 评论 0原文

我是一个初学者的网络开发人员,他正在制作我的第一个个人茉莉花套件来测试我的学校项目之一。当我为JS函数创建规格时,我遇到了一个问题,我写了一个在1到20之间生成随机数的时间。当我尝试将多个匹配器链接在一起时,发生了错误,

        it("Should return an integer value between 1 and 20.", function(){
            var rollResult=rollD20();
            expect(rollResult).toBeGreaterThanOrEqual(1).toBeLessThanOrEqual(20);
        });

我错过了简单的东西吗?有没有一种方法可以在一个语句中应用多个匹配器,或者是将其分为多个行的正确方法:

        it("Should return an integer value between 1 and 20.", function(){
            var rollResult=rollD20();
            //CHECK WITH SEAN. CAN YOU CHAIN?
            expect(rollResult).toBeGreaterThanOrEqual(1);
            expect(rollResult).toBeLessThanOrEqual(20);
        });

感谢任何帮助!我很难在文档中找到一个明确的答案。

I'm a beginner web developer who is making my first personal Jasmine suite for testing one of my school projects. I ran into an issue when creating specs for a JS function I wrote that generates a random number between 1 and 20. An error occurred when I tried to chain multiple matchers together like this

        it("Should return an integer value between 1 and 20.", function(){
            var rollResult=rollD20();
            expect(rollResult).toBeGreaterThanOrEqual(1).toBeLessThanOrEqual(20);
        });

Am I missing something simple? Is there a way to apply multiple matchers in one statement or is the proper approach to split it up into multiple lines like this:

        it("Should return an integer value between 1 and 20.", function(){
            var rollResult=rollD20();
            //CHECK WITH SEAN. CAN YOU CHAIN?
            expect(rollResult).toBeGreaterThanOrEqual(1);
            expect(rollResult).toBeLessThanOrEqual(20);
        });

I appreciate any help! I was struggled finding a clear answer in the documentation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦开始←不甜 2025-01-28 09:24:24

不幸的是,我认为您不能连锁。但是,您可以更改内部期望的内部内容。

expect(rollResult >= 1 && rollResult <= 20).toBeTrue();

我从

Unfortunately, I don't think you can chain. You can change what's inside of the expect though.

expect(rollResult >= 1 && rollResult <= 20).toBeTrue();

I got this inspiration from this answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文