Chai scripting language
You can use Chai as the default option for scripting in the Assert, Decision, and Function actions in tests, and in the Assert using Function actions in the message editor in Rational® Integration Tester. You can find information about the usage of the Chai scripting in these actions.
Chai overview
Chai is an assertion library for node.js and a browser that can be paired with any JavaScript testing framework. For more information, refer to the Chai Documentation.
- You can select Chai as an option for scripting in actions where the Rational® Integration Tester legacy scripting and ECMA scripting are supported.
- You can access the response from previous test actions in the form of a JavaScript object by using the named variables response.
- You can use the Chai function named as format that is used to check the format of the objects.
- You do not have to explicitly tag or configure other actions to expose data.
- Assert
- Expect
- Should
The Assert action is a conditional action that allows you to construct a list of expressions that determine whether a test proceeds. If the Assert action passes, the test continues. If the Assert action fails, the test fails and no further test actions are performed. See Assert.
A Decision is a conditional action, the body of which is essentially a function and whose result controls test flow. A Decision can have one of the two outcomes of true or false. See Decision.
A Function action runs a single function or composite set of functions from the registered set. Functions and expressions are loaded from a folder that is contained within the Classes folder in the project and is available to all users of the project. See Function.
You can set up assertions for the responses in tests and allow those messages that pass the defined criteria.
- CHIPS
- Fedwire
- JSON
- MIME
- SWIFT
- XML
Using the Assert Chai Style
The following examples show the usage of the Chai Assert Style:
var foo=true;
assert.isTrue(foo, "foo should be true");
assert.isAbove(5, 2, '5 is strictly greater than 2');
assert.isBelow(3, 6, '3 is strictly less than 6');
assert.isNotNull(response);
assert.isNotNull(response.header);
assert.isNotNull(response.header.Headers);
assert.exists(response);
assert.exists(response.header);
assert.exists(response.header.Headers);
assert.equal(response.header.Headers['From'],'onetest8640@gmail.com');
expect('{1:XXXXXXXXXXXX0000}{2:I101}{4::20:actual-}{5:{CHK:}}').to.be.format('swift');
expect(response.body.text).to.be.format('json');
expect(response.body.text).to.be.format('xml');
expect(response.body.text).to.be.format('mime');
Using the Expect Chai Style
expect(2).to.not.equal(1);
expect(2).to.equal(2);
expect(null).to.be.null;
expect([1, 2, 3]).to.have.lengthOf(3);
expect(response.header.Headers).to.have.property('Date');
expect(response.header.Headers).to.have.property('From');
expect(response.header.Headers).to.have.property('Content-Type');
expect(response.header.Headers['Content-Type']).to.equal('text/plain; charset=UTF-8');
Using the Should Chai Style
var name=null;
should.not.exist(name);
should.exist(response);
should.exist(response.header);