Skip to content

Commit aea248a

Browse files
committed
tests: add typescript checks
1 parent 3b3e5b8 commit aea248a

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/typescript.spec.ts

+24-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ describe('Morphism', () => {
1313
fooB: string;
1414
fooC: string;
1515
}
16-
const schema = {
16+
const schema: StrictSchema<Destination, Source> = {
1717
fooA: 'inputA',
1818
fooB: ({ inputB }) => inputB,
1919
fooC: 'inputC'
20-
} as StrictSchema<Destination, Source>;
20+
};
2121

2222
const mapper = morphism(schema);
23-
const res = mapper({}) as Destination;
23+
24+
expect(mapper({ inputA: 'test', inputB: 'test2', inputC: 'test3' })).toEqual({
25+
fooA: 'test',
26+
fooB: 'test2',
27+
fooC: 'test3'
28+
});
2429
});
2530

2631
it('should accept 2 generic parameters on Schema', () => {
@@ -31,8 +36,23 @@ describe('Morphism', () => {
3136
foo: 'inputA'
3237
};
3338
morphism(schema, { inputA: 'test' });
34-
3539
morphism(schema, [{ inputA: '' }]);
3640
});
41+
42+
it('should accept 2 generic parameters on Schema', () => {
43+
interface S {
44+
s1: string;
45+
}
46+
interface D {
47+
d1: string;
48+
}
49+
const schema: StrictSchema<D, S> = {
50+
d1: 's1'
51+
};
52+
morphism(schema)([{ s1: 'test' }]).shift().d1;
53+
morphism(schema, { s1: 'teest' }).d1.toString();
54+
morphism(schema, [{ s1: 'teest' }]).shift().d1;
55+
morphism(schema, [{ s1: 'teest' }]);
56+
});
3757
});
3858
});

src/typings.spec.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ describe('Morphism', () => {
3030
interface IFoo {
3131
foo: string;
3232
}
33-
const schema = { foo: 'bar' };
33+
const schema: Schema<IFoo> = { foo: 'bar' };
3434
const source = { bar: 'value' };
35-
const mapper = morphism<IFoo>(schema);
35+
const mapper = morphism(schema);
3636

3737
expect(mapper(source).foo).toEqual('value');
3838
expect(mapper([source][0]).foo).toEqual('value');
@@ -50,9 +50,7 @@ describe('Morphism', () => {
5050
const schema: StrictSchema<Destination, Source> = {
5151
foo: 'bar',
5252
bar: 'bar',
53-
qux: elem => {
54-
elem.bar;
55-
}
53+
qux: elem => elem.bar
5654
};
5755
const source = { bar: 'value' };
5856
// const target2 = morphism(
@@ -114,12 +112,12 @@ describe('Morphism', () => {
114112
foo: string;
115113
bar: number;
116114
}
117-
const schema: StrictSchema<IFoo> = { foo: 'qux', bar: () => 'test' };
115+
const schema: StrictSchema<IFoo> = { foo: 'qux', bar: () => 1 };
118116
const source = { qux: 'foo' };
119117
const target = morphism(schema, source);
120118

121119
expect(target.foo).toEqual(source.qux);
122-
expect(target.bar).toEqual('test');
120+
expect(target.bar).toEqual(1);
123121
});
124122
});
125123
});

0 commit comments

Comments
 (0)