Skip to content

Commit 70b47f7

Browse files
committed
improve test
1 parent 9f319c9 commit 70b47f7

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

test/models/v2/asyncapi.spec.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import { newAsyncAPIDocument } from '../../../src/models';
2-
import { V2AsyncAPIDocument } from '../../../src/models/v2/asyncapi';
3-
import { V2Info } from '../../../src/models/v2/info';
1+
import { newAsyncAPIDocument, V2AsyncAPIDocument, V2Info, V3AsyncAPIDocument } from '../../../src/models';
42

53
describe('AsyncAPIDocument model', function() {
6-
it('should create a valid document', function() {
7-
const doc = { asyncapi: "2.0.0" };
8-
const d = newAsyncAPIDocument(doc)
9-
expect(d.version()).toEqual(doc.asyncapi);
10-
});
114
describe('.version()', function() {
125
it('should return the value', function() {
136
const doc = { asyncapi: "3.0.0" };
@@ -30,3 +23,22 @@ describe('AsyncAPIDocument model', function() {
3023
});
3124
});
3225
});
26+
27+
describe('AsyncAPIDocument factory', function() {
28+
it('should create a valid document from v2.0.0', function() {
29+
const doc = { asyncapi: "2.0.0" };
30+
const d = newAsyncAPIDocument(doc)
31+
expect(d.version()).toEqual(doc.asyncapi);
32+
expect(d).toBeInstanceOf(V2AsyncAPIDocument);
33+
});
34+
it('should create a valid document from v3.0.0', function() {
35+
const doc = { asyncapi: "3.0.0" };
36+
const d = newAsyncAPIDocument(doc)
37+
expect(d.version()).toEqual(doc.asyncapi);
38+
expect(d).toBeInstanceOf(V3AsyncAPIDocument);
39+
});
40+
it('should fail trying to create a document from a non supported spec version', function() {
41+
const doc = { asyncapi: "99.99.99" };
42+
expect(() => newAsyncAPIDocument(doc)).toThrow("Unsupported version: 99.99.99");
43+
});
44+
});

0 commit comments

Comments
 (0)