Skip to content

Commit aeb33b7

Browse files
Rasmus SybergMTschannett
authored andcommitted
Added tests for testForBuffer
1 parent 7c45fc7 commit aeb33b7

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/TransformOperationExecutor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,10 @@ function instantiateArrayType(arrayType: Function): Array<any> | Set<any> {
419419
return array;
420420
}
421421

422-
function testForBuffer(): boolean {
422+
export function testForBuffer(): boolean {
423423
try {
424424
Buffer
425425
return true;
426-
} catch {}
427-
return false;
426+
} catch { }
427+
return false;
428428
}

test/functional/basic-functionality.spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@ import {
66
plainToClassFromExist,
77
classToClass, classToClassFromExist
88
} from "../../src/index";
9-
import {defaultMetadataStorage} from "../../src/storage";
10-
import {Exclude, Expose, Type} from "../../src/decorators";
11-
import {expect} from "chai";
9+
import { defaultMetadataStorage } from "../../src/storage";
10+
import { Exclude, Expose, Type } from "../../src/decorators";
11+
import { expect } from "chai";
12+
import { testForBuffer } from "../../src/TransformOperationExecutor";
1213

1314
describe("basic functionality", () => {
1415

16+
it("should return true if Buffer is present in environment, else false", () => {
17+
expect(testForBuffer()).to.be.true;
18+
const bufferImp = global.Buffer;
19+
delete global.Buffer;
20+
expect(testForBuffer()).to.be.false;
21+
global.Buffer = bufferImp;
22+
});
23+
1524
it("should convert instance of the given object to plain javascript object and should expose all properties since its a default behaviour", () => {
1625
defaultMetadataStorage.clear();
1726

0 commit comments

Comments
 (0)