Skip to content

Commit ed15317

Browse files
committed
test keeping instances with buffers etc
1 parent 28daef7 commit ed15317

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

packages/oats-runtime/test/make-from-reflection.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as classWithAdditional from './test-class-with-additional-props';
55
import { Type } from '../src/reflection-type';
66
import { serialize } from '../src/serialize';
77
import { getType, withType } from '../src/type-tag';
8+
import { File, FormBinary } from '../src/make';
89

910
describe('union differentation', () => {
1011
it('handles cases where union children are missing the tag', () => {
@@ -408,6 +409,30 @@ describe('unknown', () => {
408409
expect(fun(item).success()).toEqual(item);
409410
expect(fun(item).success() !== item).toBeTruthy();
410411
});
412+
it('keeps Buffer instances', async () => {
413+
const fun = make.fromReflection({ type: 'unknown' });
414+
const item = Buffer.alloc(1, 'x', 'utf-8');
415+
expect(fun(item).success()).toEqual(item);
416+
expect(fun(item).success() === item).toBeTruthy();
417+
});
418+
it('keeps File instances', async () => {
419+
const fun = make.fromReflection({ type: 'unknown' });
420+
const item = new File('path', 10, 'name');
421+
expect(fun(item).success()).toEqual(item);
422+
expect(fun(item).success() === item).toBeTruthy();
423+
});
424+
it('keeps FormBinary instances', async () => {
425+
const fun = make.fromReflection({ type: 'unknown' });
426+
const item = new FormBinary({ binary: Buffer.alloc(1, 'x', 'utf-8') });
427+
expect(fun(item).success()).toEqual(item);
428+
expect(fun(item).success() === item).toBeTruthy();
429+
});
430+
it('keeps FormBinary instances', async () => {
431+
const fun = make.fromReflection({ type: 'unknown' });
432+
const item = new FormBinary({ binary: Buffer.alloc(1, 'x', 'utf-8') });
433+
expect(fun(item).success()).toEqual(item);
434+
expect(fun(item).success() === item).toBeTruthy();
435+
});
411436
it('keeps custom instances', async () => {
412437
const fun = make.fromReflection({ type: 'unknown' });
413438
const item = new SomeClass();

0 commit comments

Comments
 (0)