No results for

Powered byAlgolia

toHaveValidJson( )

suggest edits

toHaveValidJson() validates that the http response has valid JSON body. It must be called in the chain after the t.expect(response) or .and(response).

When toHaveValidJson() returns false, the chain is broken, and the test is marked as failed. When the chain is broken, further checks inside of the test are omitted.

Returns

TypeDescription
FunkFunk object

Example

import { describe } from 'https://jslib.k6.io/expect/0.0.4/index.js';
import http from 'k6/http';
export default function testSuite() {
describe('Basic test', (t) => {
const response = http.get('https://test-api.k6.io/public/crocodiles');
t.expect(response)
.toHaveValidJson()
.and(response.json().length)
.as('number of crocs')
.toBeGreaterThan(5);
});
}