diff --git a/test/website-docs.spec.js b/test/website-docs.spec.js index 436744f77402ef359a96d653fb9bf6f59c203eea..53483b2bbf3ee157506f39bf3cdfacc5157987ce 100644 --- a/test/website-docs.spec.js +++ b/test/website-docs.spec.js @@ -51,4 +51,41 @@ describe('docs', () => { it('has headers for every required sub-option', () => { expect(headers3).toEqual(expectedOptions3); }); + + // Checking relatedOptions field in definitions + let relatedOptions = options + .filter(option => option.relatedOptions) + .map(option => option.relatedOptions) + .sort(); + + relatedOptions = [].concat(...relatedOptions); // Converts the matrix to an 1D array + relatedOptions = [...new Set(relatedOptions)]; // Makes all options unique + + /* + Matcher which checks if the argument is within the received array (or string) + on an error, it throws a custom message. + */ + expect.extend({ + toContainOption(received, argument) { + if (received.includes(argument)) { + return { + message: () => `Option "${argument}" should be within definitions`, + pass: true, + }; + } + return { + message: () => `Option "${argument}" doesn't exist within definitions`, + pass: false, + }; + }, + }); + + const allOptionNames = options.map(option => option.name).sort(); + + // Lists through each option in the relatedOptions array to be able to locate the exact element which causes error, in case of one + it('has valid relateOptions values', () => { + relatedOptions.forEach(relOption => { + expect(allOptionNames).toContainOption(relOption); + }); + }); });