Vanilla k6 over K6chaijs

Hi @Tom & @mstoykov

I checked K6chaijs repo

It looks similar to the vanilla k6. Instead of groups and checks It uses chai assertion. Can someone explain what are the advantages or features I can get it over vanilla k6 with the help of K6chaijs.

Hey Gerard,

please see the documentation for k6chajs and also the explanation about why this library has better error handling than the default k6.

Here’s a short excerpt from the documentation:

k6chajs Assertion Library is an assertion library that is paired with k6 to provide a more developer-friendly BDD and TDD assertion style. It’s a more powerful alternative to the k6-native check() and group().

This library is recommended for any type of testing, but especially for:

  • Functional testing, where many asserts are needed.
  • Stress testing, where the System Under Test is failing and the test code needs to stay robust.
  • Load testing, when the test should abort as soon as the first failure occurs.
  • Unit testing of JavaScript code, which is not necessarily connected with load.
  • JavaScript Developers, who are already familiar with Chai, Jest or Jasmine.
3 Likes

Hi @zakirefai your (now closed) issue related to the 504 errors reminded me of this issue.

I also wanted to suggest consider switching to the k6chaijs library for error handling and other advantages. This is relevant to both the iteration and the specific request.

By chaining the expects (chai checks) in a logical order, it will reduce the # of expects which are run. No extra code involved. For example, test the response status code before attempting to test the JSON response body.

Also: if a specific describe (chai group) fails, the test execution of that iteration will continue outside of that describe.

More information: Using chai with k6
and: https://grafana.com/docs/k6/latest/javascript-api/jslib/k6chaijs/error-handling/

1 Like