function queryEndpoint(endpoint) { return fetch(`https://api.ciscospark.com/v1/${endpoint}`, { headers: { Authorization: `Bearer ${TOKEN}` } }).then(response => { if (response.ok) { return response.json(); } else { throw new Error(`Failed to query endpoint: ${endpoint}: ${response.status} ${response.statusText}`); } }); }
describe('queryEndpoint', () => { it('should reject Promise when given invalid endpoint', () => { return assert.isRejected(queryEndpoint('invalid-endpoint'), /Failed to query endpoint/); }); });This test uses the assert.isRejected() function to assert that the Promise returned by queryEndpoint('invalid-endpoint') is rejected with an error message that matches the regular expression /Failed to query endpoint/. If the Promise is not rejected or the error message does not match the regular expression, the test will fail. In summary, @ciscospark.test-helper-chai is a package library that provides utility functions and assertions for testing Cisco Spark applications using the Chai assertion framework. The assert.isRejected() function is one such assertion that can be used to test if an asynchronous operation throws an error or rejects a Promise.