JDevenyi
JDevenyi

Reputation: 111

Can you chain multiple Jasmine matchers?

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.

Upvotes: 0

Views: 342

Answers (1)

AliF50
AliF50

Reputation: 18809

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.

Upvotes: 1

Related Questions