Skip to content

Commit

Permalink
test: metadata.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Oct 19, 2022
1 parent 78552d3 commit 8d5f8aa
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
17 changes: 17 additions & 0 deletions test/unit/__snapshots__/metadata.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Vitest Snapshot v1

exports[`Metadata Object > get commentID() 1`] = `undefined`;

exports[`Metadata Object > get commentID() 2`] = `undefined`;

exports[`Metadata Object > get commentID() 3`] = `"123456789"`;

exports[`Metadata Object > get commentID() 4`] = `"123456789"`;

exports[`Metadata Object > get tag() 1`] = `undefined`;

exports[`Metadata Object > get tag() 2`] = `"v1"`;

exports[`Metadata Object > get tag() 3`] = `undefined`;

exports[`Metadata Object > get tag() 4`] = `"v1"`;
11 changes: 10 additions & 1 deletion test/unit/fixtures/metadata.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ export interface IMetadataTestContext {
}

export const metadataContextFixture: IMetadataTestContext = {
metadata: [new Metadata({ tag: undefined, commentID: undefined })],
metadata: [
new Metadata({ tag: undefined, commentID: undefined }),
new Metadata({ tag: 'v1', commentID: undefined }),
new Metadata({ tag: undefined, commentID: '123456789' }),
new Metadata({ tag: 'v1', commentID: '123456789' }),
],

invalid: [
// @ts-expect-error: Let's ignore a type error, it's required for testing
Expand All @@ -21,5 +26,9 @@ export const metadataContextFixture: IMetadataTestContext = {
new Metadata({}),
// @ts-expect-error: Let's ignore a type error, it's required for testing
new Metadata([]),
// @ts-expect-error: Let's ignore a type error, it's required for testing
new Metadata({ tag: null, commentID: null }),
// @ts-expect-error: Let's ignore a type error, it's required for testing
new Metadata({ tag: undefined, commentID: 123456789 }),
],
};
32 changes: 28 additions & 4 deletions test/unit/metadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { describe, it, expect, beforeEach, test } from 'vitest';

import {
metadataContextFixture,
Expand All @@ -11,7 +11,31 @@ describe('Metadata Object', () => {
context.invalid = metadataContextFixture.invalid;
});

it<IMetadataTestContext>('can be instantiated', context => {
context.metadata.map(item => expect(item).toBeDefined());
});
it<IMetadataTestContext>('can be instantiated', context =>
context.metadata.map(metadataItem => expect(metadataItem).toBeDefined()));

it.todo<IMetadataTestContext>(
'is invalid' /*, async context => {
context.invalid.map(async item =>
expect(Metadata.validate(item)).resolves.toMatchSnapshot()
);
}*/
);

test<IMetadataTestContext>('get tag()', context =>
context.metadata.map(metadataItem =>
expect(metadataItem.tag).toMatchSnapshot()
));

test.todo<IMetadataTestContext>('set tag()');

test<IMetadataTestContext>('get commentID()', context =>
context.metadata.map(metadataItem =>
expect(metadataItem.commentID).toMatchSnapshot()
));

test.todo<IMetadataTestContext>('set commentID()');

test.todo<IMetadataTestContext>('getMetadata()');
test.todo<IMetadataTestContext>('setMetadata()');
});

0 comments on commit 8d5f8aa

Please sign in to comment.