Some additional small tests (#429)
* Some additional small tests * Missing MemoryDb from previous commit
This commit is contained in:
@@ -39,6 +39,14 @@ describe('encode', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('encodes basic u32 values (< 2^30)', () => {
|
||||
expect(
|
||||
compactToU8a(0x1fff)
|
||||
).toEqual(
|
||||
new Uint8Array([253, 127])
|
||||
);
|
||||
});
|
||||
|
||||
it('encodes basic u32 values (short)', () => {
|
||||
expect(
|
||||
compactToU8a(0xffff)
|
||||
|
||||
@@ -4,19 +4,31 @@
|
||||
|
||||
describe('Array.fill', () => {
|
||||
let arrayFill: any;
|
||||
let u8aFill: any;
|
||||
|
||||
beforeEach(() => {
|
||||
arrayFill = Array.prototype.fill;
|
||||
Array.prototype.fill = null as any;
|
||||
u8aFill = Uint8Array.prototype.fill;
|
||||
|
||||
// @ts-ignore
|
||||
Array.prototype.fill = null;
|
||||
// @ts-ignore
|
||||
Uint8Array.prototype.fill = null;
|
||||
|
||||
require('./fill');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
Array.prototype.fill = arrayFill;
|
||||
Uint8Array.prototype.fill = u8aFill;
|
||||
});
|
||||
|
||||
it('uses the polyfills', () => {
|
||||
expect([1, 2, 3, 4, 5, 6, 7, 8].fill(5, 3)).toEqual([1, 2, 3, 5, 5, 5, 5, 5]);
|
||||
expect(
|
||||
[1, 2, 3, 4, 5, 6, 7, 8].fill(5, 3)
|
||||
).toEqual([1, 2, 3, 5, 5, 5, 5, 5]);
|
||||
expect(
|
||||
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]).fill(5, 3)
|
||||
).toEqual(new Uint8Array([1, 2, 3, 5, 5, 5, 5, 5]));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2017-2019 @polkadot/util authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
describe('setPrototypeOf', () => {
|
||||
let orig: (o: any, proto: object | null) => any;
|
||||
|
||||
beforeEach(() => {
|
||||
orig = Object.setPrototypeOf;
|
||||
|
||||
// @ts-ignore
|
||||
Object.setPrototypeOf = null;
|
||||
|
||||
require('./setPrototypeOf');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
Object.setPrototypeOf = orig;
|
||||
});
|
||||
|
||||
it('polyfills with no exceptions', () => {
|
||||
const obj = {};
|
||||
const proto = { foo: 'bar' };
|
||||
|
||||
expect(Object.setPrototypeOf(obj, proto).__proto__).toBe(proto);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user