Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions integration/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ const browser = puppeteer.launch({ headless: false });

const rootUrl = "http://localhost:3000/public/index.html";

// Returns a promise that rejects and fails the test when the page produces an
// error message on the console, and never resolves (so don't await it but
// combine it using Promise.race() - if you don't, the test will still fail, but
// you'll get an UnhandledPromiseRejectionWarning from node).
function failOnErrorMessage(page) {
return new Promise((resolve, reject) => {
page.on('console', msg => {
if ((msg.type() === "error" && !msg.location().url.includes('favicon.ico')) || msg.text().startsWith('oops')) {
Promise.all(msg.args().map(h => h.evaluate(a => a.toString())))
.then(args => expect({"console message": args}).toBeUndefined())
.catch(e => reject(e));
}
});
});
}

beforeAll( async () => { await server }, 50000 );
afterAll( async () => {
( await server ).close();
Expand Down Expand Up @@ -103,3 +119,23 @@ test('pretty big schema', async () => {

expect(results).toContain( 'All documents and attachments related to the contract, including any notices.' );
});

test('additionalProperties', async () => {
const page = await ( await browser ).newPage();
let errorOccurred = failOnErrorMessage(page);

await page.goto( rootUrl + "#/integration/schemas/additionalProperties.json");

async function textAtPath(path) {
let element = await page.waitFor(path);
return await element.evaluate(e => e.textContent.trim());
}
await Promise.race([
Promise.all([
expect(textAtPath('#doc .box .signature:nth-child(2) .property-name')).resolves.toBe('foo'),
expect(textAtPath('#doc .box .signature:nth-child(3) .property-name')).resolves.toBe('bar'),
expect(textAtPath('#doc .box .signature:nth-child(4) .box .signature-type')).resolves.toBe('boolean')
]),
errorOccurred
]);
});
4 changes: 4 additions & 0 deletions integration/schemas/additionalProperties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"properties": {"foo": {}, "bar": {}},
"additionalProperties": {"type": "boolean"}
}
2 changes: 1 addition & 1 deletion public/templates/box.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<div class="signature-header">
<div class="property-name type-pattern">additional</div>
<div class="signature-type">
{{schema ../additionalProperties}}
{{schema additionalProperties}}
</div>
</div>
</div>
Expand Down