mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-10 19:06:34 +03:00
Migrate tests to jasmine instead of macha (angular testing depends on jasmine)
This commit is contained in:
parent
832d018c1b
commit
36c51dee3d
|
@ -3,7 +3,7 @@
|
|||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"browser": true,
|
||||
"mocha": true
|
||||
"jasmine": true
|
||||
},
|
||||
// currently eslint doesn't support extension-typed configs
|
||||
"globals": {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module.exports = function (config) {
|
||||
var travis = process.env.TRAVIS;
|
||||
config.set({
|
||||
frameworks: ['phantomjs-shim', 'jspm', 'mocha', 'chai', 'sinon'],
|
||||
frameworks: ['phantomjs-shim', 'jspm', 'jasmine', 'sinon', 'should'],
|
||||
preprocessors: {
|
||||
'lib/**/!(*spec).js': ['babel', 'coverage']
|
||||
},
|
||||
|
@ -46,8 +46,8 @@ module.exports = function (config) {
|
|||
|
||||
jspm: {
|
||||
config: 'system.config.js',
|
||||
loadFiles: ['tests/**/*.spec.js', 'lib/**/*.js'],
|
||||
serveFiles: ['tests/schemas/**/*.json'],
|
||||
loadFiles: ['tests/**/*.spec.js', 'tests/helpers.js', 'lib/**/*.js'],
|
||||
serveFiles: ['tests/schemas/**/*.json', 'lib/**/*.{html,css}'],
|
||||
nocache: true
|
||||
},
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ describe('BaseComponent', () => {
|
|||
let schemaMgr;
|
||||
let component;
|
||||
|
||||
before(() => {
|
||||
beforeAll(() => {
|
||||
schemaMgr = new SchemaManager();
|
||||
schemaMgr._schema = {tags: []};
|
||||
});
|
||||
|
@ -18,8 +18,8 @@ describe('BaseComponent', () => {
|
|||
|
||||
it('should set instance properties', () => {
|
||||
component.schemaMgr.should.be.equal(schemaMgr);
|
||||
component.schema.should.be.an('object');
|
||||
expect(component.componentSchema).to.not.exist;
|
||||
component.schema.should.be.of.type('object');
|
||||
expect(component.componentSchema).toBeNull();
|
||||
});
|
||||
|
||||
it('should set componentSchema based on pointer on ngOnInit', () => {
|
||||
|
@ -37,13 +37,15 @@ describe('BaseComponent', () => {
|
|||
});
|
||||
|
||||
describe('dereference', () => {
|
||||
before(() => {
|
||||
return schemaMgr.load('/tests/schemas/base-component-dereference.json');
|
||||
beforeAll((done) => {
|
||||
schemaMgr.load('/tests/schemas/base-component-dereference.json').then(
|
||||
() => done()
|
||||
);
|
||||
});
|
||||
|
||||
describe('simple dereference', () => {
|
||||
let paramWithRef;
|
||||
before(() => {
|
||||
beforeAll(() => {
|
||||
component.pointer = '/paths/test1/get';
|
||||
component.ngOnInit();
|
||||
component.dereference();
|
||||
|
@ -51,7 +53,7 @@ describe('BaseComponent', () => {
|
|||
});
|
||||
|
||||
it('should not contain $ref property', () => {
|
||||
expect(paramWithRef.$ref).to.not.exist;
|
||||
expect(paramWithRef.$ref).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should inject Title if not exist based on reference', () => {
|
||||
|
@ -65,13 +67,13 @@ describe('BaseComponent', () => {
|
|||
it('should insert correct definition instead of reference', () => {
|
||||
delete paramWithRef.title;
|
||||
delete paramWithRef._pointer;
|
||||
paramWithRef.should.be.deep.equal(schemaMgr.schema.definitions.Simple);
|
||||
paramWithRef.should.be.deepEqual(schemaMgr.schema.definitions.Simple);
|
||||
});
|
||||
});
|
||||
|
||||
describe('nested dereference', () => {
|
||||
let paramWithRef;
|
||||
before(() => {
|
||||
beforeAll(() => {
|
||||
component.pointer = '/paths/test2/get';
|
||||
component.ngOnInit();
|
||||
component.dereference();
|
||||
|
@ -83,7 +85,7 @@ describe('BaseComponent', () => {
|
|||
});
|
||||
|
||||
it('should resolve nested schema', () => {
|
||||
expect(paramWithRef.properties.subschema.$ref).to.not.exist;
|
||||
expect(paramWithRef.properties.subschema.$ref).toBeUndefined();
|
||||
paramWithRef._pointer.should.be.equal('#/definitions/Nested');
|
||||
paramWithRef.properties.subschema._pointer.should.be.equal('#/definitions/Simple');
|
||||
paramWithRef.properties.subschema.type.should.be.equal('object');
|
||||
|
@ -92,7 +94,7 @@ describe('BaseComponent', () => {
|
|||
|
||||
describe('array schema dereference', () => {
|
||||
let paramWithRef;
|
||||
before(() => {
|
||||
beforeAll(() => {
|
||||
component.pointer = '/paths/test3/get';
|
||||
component.ngOnInit();
|
||||
component.dereference();
|
||||
|
@ -100,8 +102,8 @@ describe('BaseComponent', () => {
|
|||
});
|
||||
|
||||
it('should resolve array schema', () => {
|
||||
expect(paramWithRef.$ref).to.not.exist;
|
||||
expect(paramWithRef.items.schema.$ref).to.not.exist;
|
||||
expect(paramWithRef.$ref).toBeUndefined();
|
||||
expect(paramWithRef.items.schema.$ref).toBeUndefined();
|
||||
paramWithRef.type.should.be.equal('array');
|
||||
paramWithRef._pointer.should.be.equal('#/definitions/ArrayOfSimple');
|
||||
paramWithRef.items.schema._pointer.should.be.equal('#/definitions/Simple');
|
||||
|
@ -111,13 +113,13 @@ describe('BaseComponent', () => {
|
|||
});
|
||||
|
||||
describe('mergeAllOf', () => {
|
||||
before(() => {
|
||||
return schemaMgr.load('tests/schemas/base-component-joinallof.json');
|
||||
beforeAll((done) => {
|
||||
schemaMgr.load('tests/schemas/base-component-joinallof.json').then(() => done());
|
||||
});
|
||||
|
||||
describe('Simple allOf merge', () => {
|
||||
let joined;
|
||||
before(() => {
|
||||
beforeAll(() => {
|
||||
component.pointer = '/definitions/SimpleAllOf';
|
||||
component.ngOnInit();
|
||||
component.dereference();
|
||||
|
@ -126,7 +128,7 @@ describe('BaseComponent', () => {
|
|||
});
|
||||
|
||||
it('should remove $allOf field', () => {
|
||||
expect(joined.allOf).to.not.exist;
|
||||
expect(joined.allOf).toBeNull();
|
||||
});
|
||||
|
||||
it('should set type object', () => {
|
||||
|
@ -135,18 +137,18 @@ describe('BaseComponent', () => {
|
|||
|
||||
it('should merge properties', () => {
|
||||
Object.keys(joined.properties).length.should.be.equal(3);
|
||||
Object.keys(joined.properties).should.be.deep.equal(['prop1', 'prop2', 'prop3']);
|
||||
Object.keys(joined.properties).should.be.deepEqual(['prop1', 'prop2', 'prop3']);
|
||||
});
|
||||
|
||||
it('should merge required', () => {
|
||||
joined.required.length.should.be.equal(2);
|
||||
joined.required.should.be.deep.equal(['prop1', 'prop3']);
|
||||
joined.required.should.be.deepEqual(['prop1', 'prop3']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('AllOf with refrence', () => {
|
||||
let joined;
|
||||
before(() => {
|
||||
beforeAll(() => {
|
||||
component.pointer = '/definitions/AllOfWithRef';
|
||||
component.ngOnInit();
|
||||
component.dereference();
|
||||
|
@ -155,7 +157,7 @@ describe('BaseComponent', () => {
|
|||
});
|
||||
|
||||
it('should remove $allOf field', () => {
|
||||
expect(joined.allOf).to.not.exist;
|
||||
expect(joined.allOf).toBeNull();
|
||||
});
|
||||
|
||||
it('should set type object', () => {
|
||||
|
@ -164,12 +166,12 @@ describe('BaseComponent', () => {
|
|||
|
||||
it('should merge properties', () => {
|
||||
Object.keys(joined.properties).length.should.be.equal(2);
|
||||
Object.keys(joined.properties).should.be.deep.equal(['id', 'prop3']);
|
||||
Object.keys(joined.properties).should.be.deepEqual(['id', 'prop3']);
|
||||
});
|
||||
|
||||
it('should merge required', () => {
|
||||
joined.required.length.should.be.equal(2);
|
||||
joined.required.should.be.deep.equal(['id', 'prop3']);
|
||||
joined.required.should.be.deepEqual(['id', 'prop3']);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -178,18 +180,18 @@ describe('BaseComponent', () => {
|
|||
component.pointer = '/definitions/BadAllOf2';
|
||||
component.ngOnInit();
|
||||
component.dereference();
|
||||
component.joinAllOf.bind(component).should.throw();
|
||||
(() => component.joinAllOf()).should.throw();
|
||||
});
|
||||
|
||||
it('should throw when merging non-object schemas', () => {
|
||||
component.pointer = '/definitions/BadAllOf1';
|
||||
component.ngOnInit();
|
||||
component.dereference();
|
||||
component.joinAllOf.bind(component).should.throw();
|
||||
(() => component.joinAllOf()).should.throw();
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('Merge array allOf', () => {
|
||||
xdescribe('Merge array allOf', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
export function statusCodeType(statusCode) {
|
||||
if (statusCode < 100 || statusCode > 599) {
|
||||
throw 'invalid HTTP code';
|
||||
throw new Error('invalid HTTP code');
|
||||
}
|
||||
let res = 'success';
|
||||
if (statusCode >= 300 && statusCode < 400) {
|
||||
|
|
11
package.json
11
package.json
|
@ -54,7 +54,6 @@
|
|||
"babel-eslint": "^4.1.3",
|
||||
"babel-polyfill": "^6.3.14",
|
||||
"browser-sync": "^2.9.8",
|
||||
"chai": "^3.4.1",
|
||||
"del": "^2.0.2",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-concat": "^2.6.0",
|
||||
|
@ -66,28 +65,30 @@
|
|||
"gulp-sourcemaps": "^1.6.0",
|
||||
"isparta": "^4.0.0",
|
||||
"istanbul": "github:gotwarlost/istanbul#source-map",
|
||||
"jasmine-core": "^2.4.1",
|
||||
"jshint-stylish": "^2.0.1",
|
||||
"jspm": "^0.16.11",
|
||||
"karma": "^0.13.15",
|
||||
"karma-babel-preprocessor": "^5.2.2",
|
||||
"karma-chai": "github:randing89/karma-chai",
|
||||
"karma-chrome-launcher": "^0.2.2",
|
||||
"karma-coverage": "github:douglasduteil/karma-coverage#next",
|
||||
"karma-coveralls": "^1.1.2",
|
||||
"karma-jasmine": "^0.3.6",
|
||||
"karma-jspm": "^2.0.2",
|
||||
"karma-mocha": "^0.2.1",
|
||||
"karma-mocha-reporter": "^1.1.3",
|
||||
"karma-phantomjs-launcher": "^0.2.1",
|
||||
"karma-phantomjs-shim": "^1.1.2",
|
||||
"karma-should": "^1.0.0",
|
||||
"karma-sinon": "^1.0.4",
|
||||
"mocha": "^2.3.4",
|
||||
"phantomjs": "^1.9.19",
|
||||
"reflect-metadata": "^0.1.2",
|
||||
"require-dir": "^0.3.0",
|
||||
"run-sequence": "^1.1.4",
|
||||
"should": "^8.0.1",
|
||||
"sinon": "^1.9.0",
|
||||
"systemjs-builder": "^0.14.7",
|
||||
"vinyl-paths": "^2.0.0",
|
||||
"zone.js": "^0.5.8"
|
||||
}
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ describe('JsonPointer', () => {
|
|||
});
|
||||
|
||||
it('should handle relative pointers (starting with #) without errors', ()=> {
|
||||
JsonPointer.parse('#/level1/level2/name').should.be.deep.equal(['level1', 'level2', 'name']);
|
||||
JsonPointer.parse('#/level1/level2/name').should.be.deepEqual(['level1', 'level2', 'name']);
|
||||
});
|
||||
|
||||
it('should join correctly', ()=> {
|
||||
|
|
|
@ -38,7 +38,7 @@ describe('Schema manager', () => {
|
|||
});
|
||||
|
||||
describe('Schema manager basic functionality', ()=> {
|
||||
before(function (done) {
|
||||
beforeAll(function (done) {
|
||||
schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => {
|
||||
done();
|
||||
}, () => {
|
||||
|
@ -48,7 +48,7 @@ describe('Schema manager', () => {
|
|||
|
||||
|
||||
it('should contain non-empty schema', ()=> {
|
||||
schemaMgr.schema.should.be.an('object');
|
||||
schemaMgr.schema.should.be.an.Object();
|
||||
schemaMgr.schema.should.be.not.empty;
|
||||
});
|
||||
|
||||
|
@ -59,19 +59,19 @@ describe('Schema manager', () => {
|
|||
describe('byPointer method', () => {
|
||||
it('should return correct schema part', ()=> {
|
||||
let part = schemaMgr.byPointer('/tags/3');
|
||||
part.should.be.deep.equal(schemaMgr.schema.tags[3]);
|
||||
part.should.be.deepEqual(schemaMgr.schema.tags[3]);
|
||||
part.should.be.equal(schemaMgr.schema.tags[3]);
|
||||
});
|
||||
|
||||
it('should return null for incorrect pointer', ()=> {
|
||||
let part = schemaMgr.byPointer('/incorrect/pointer');
|
||||
should.not.exist(part);
|
||||
expect(part).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getTagsMap method', () => {
|
||||
before(function () {
|
||||
beforeAll(function () {
|
||||
schemaMgr._schema = {
|
||||
tags: [
|
||||
{name: 'tag1', description: 'info1'},
|
||||
|
@ -86,7 +86,7 @@ describe('Schema manager', () => {
|
|||
tag1: {description: 'info1', 'x-traitTag': false},
|
||||
tag2: {description: 'info2', 'x-traitTag': true}
|
||||
};
|
||||
tagsMap.should.be.deep.equal(expectedResult);
|
||||
tagsMap.should.be.deepEqual(expectedResult);
|
||||
});
|
||||
|
||||
it('should return empty array for non-specified tags', () => {
|
||||
|
@ -123,7 +123,7 @@ describe('Schema manager', () => {
|
|||
let menuTree;
|
||||
let entries;
|
||||
|
||||
before(() => {
|
||||
beforeAll(() => {
|
||||
schemaMgr._schema = suitSchema;
|
||||
menuTree = schemaMgr.buildMenuTree();
|
||||
entries = Array.from(menuTree.entries());
|
||||
|
@ -161,12 +161,12 @@ describe('Schema manager', () => {
|
|||
it('methods for tag should contain valid pointer and summary', () => {
|
||||
for (let entr of entries) {
|
||||
let [, info] = entr;
|
||||
info.should.be.an('object');
|
||||
info.methods.should.be.an('array');
|
||||
info.should.be.an.Object();
|
||||
info.methods.should.be.an.Array();
|
||||
for (let methodInfo of info.methods) {
|
||||
methodInfo.should.include.keys('pointer', 'summary');
|
||||
methodInfo.should.have.keys('pointer', 'summary');
|
||||
let methSchema = schemaMgr.byPointer(methodInfo.pointer);
|
||||
should.exist(methSchema);
|
||||
expect(methSchema).not.toBeNull();
|
||||
if (methSchema.summary) {
|
||||
methSchema.summary.should.be.equal(methodInfo.summary);
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ describe('Schema manager', () => {
|
|||
});
|
||||
|
||||
describe('getMethodParams method', () => {
|
||||
before((done) => {
|
||||
beforeAll((done) => {
|
||||
schemaMgr.load('/tests/schemas/schema-mgr-methodparams.json').then(() => {
|
||||
done();
|
||||
}, () => {
|
||||
|
@ -199,7 +199,7 @@ describe('Schema manager', () => {
|
|||
|
||||
it('should accept pointer directly to parameters', () => {
|
||||
let params = schemaMgr.getMethodParams('/paths/test1/get/parameters', true);
|
||||
expect(params).to.exist;
|
||||
expect(params).not.toBeNull();
|
||||
params.length.should.be.equal(2);
|
||||
});
|
||||
|
||||
|
@ -220,7 +220,7 @@ describe('Schema manager', () => {
|
|||
|
||||
it('should throw for parameters other than array', () => {
|
||||
let func = () => schemaMgr.getMethodParams('/paths/test4/get', true);
|
||||
func.should.throw();
|
||||
expect(func).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ describe('KeysPipe and ValuesPipe', () => {
|
|||
describe('KeysPipe transform', () => {
|
||||
it('should return keys', () => {
|
||||
var val = keysPipe.transform(obj);
|
||||
val.should.be.deep.equal(['a', 'b', 'c']);
|
||||
val.should.be.deepEqual(['a', 'b', 'c']);
|
||||
});
|
||||
|
||||
it('should not support other objects', () => {
|
||||
|
@ -35,7 +35,7 @@ describe('KeysPipe and ValuesPipe', () => {
|
|||
describe('KeysPipe transform', () => {
|
||||
it('should return values', () => {
|
||||
var val = valuesPipe.transform(obj);
|
||||
val.should.be.deep.equal([1, 2, 3]);
|
||||
val.should.be.deepEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
it('should not support other objects', () => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user