mirror of
https://github.com/Redocly/redoc.git
synced 2025-05-30 10:43:04 +03:00
Add a few schema-manager tests
This commit is contained in:
parent
ed56dcc3b6
commit
8c814f9fc0
|
@ -12,6 +12,7 @@ module.exports = function (config) {
|
||||||
jspm: {
|
jspm: {
|
||||||
config: 'system.config.js',
|
config: 'system.config.js',
|
||||||
loadFiles: ['tests/**/*.spec.js', 'lib/**/*.js'],
|
loadFiles: ['tests/**/*.spec.js', 'lib/**/*.js'],
|
||||||
|
serveFiles: ['tests/schemas/**/*.json'],
|
||||||
nocache: true
|
nocache: true
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -14,29 +14,43 @@ describe("Schema manager", () => {
|
||||||
(new SchemaManager()).should.be.equal(schemaMgr);
|
(new SchemaManager()).should.be.equal(schemaMgr);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("load method", ()=> {
|
it("load should return a promise", ()=> {
|
||||||
let req = null;
|
schemaMgr.load('/tests/schemas/extended-petstore.json').should.be.instanceof(Promise);
|
||||||
let xhr = null;
|
});
|
||||||
before(function () {
|
|
||||||
// fake XHR
|
it("load should resolve promise for valid url", (done)=> {
|
||||||
xhr = sinon.useFakeXMLHttpRequest();
|
schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => {
|
||||||
|
done();
|
||||||
|
}, (err) => {
|
||||||
|
throw new Error("Error handler should not be called")
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Schema manager with loaded schema", ()=> {
|
||||||
it("should return a promise", ()=> {
|
before(function (done) {
|
||||||
schemaMgr.load('http://test').should.be.instanceof(Promise);
|
schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => {
|
||||||
});
|
|
||||||
|
|
||||||
it("should reject promise for non-existing schema", (done)=> {
|
|
||||||
schemaMgr.load('http://test').then(() => {
|
|
||||||
throw new Error("Should not be called")
|
|
||||||
}, (err) => {
|
|
||||||
done();
|
done();
|
||||||
|
}, (err) => {
|
||||||
|
throw new Error("Error handler should not be called")
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function () {
|
|
||||||
xhr.restore();
|
it("should contain non-empty schema", ()=> {
|
||||||
|
schemaMgr.schema.should.be.an("object");
|
||||||
|
schemaMgr.schema.should.be.not.empty;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should correctly init api url", ()=> {
|
||||||
|
schemaMgr.apiUrl.should.be.equal("http://petstore.swagger.io/v2");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("byPointer should return correct schema part", ()=> {
|
||||||
|
var part = schemaMgr.byPointer('/tags/3');
|
||||||
|
part.should.be.deep.equal({
|
||||||
|
name: "store",
|
||||||
|
description: "Access to Petstore orders"
|
||||||
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user