Skip to content

Commit

Permalink
fix: type coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Feb 14, 2020
1 parent 8186e19 commit 0ff1ae7
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/__tests__/Context.ts
Expand Up @@ -3,19 +3,18 @@ import { Context } from '~/Context';
import { ImportMock } from 'ts-mock-imports';
import * as polkadotModule from '@polymathnetwork/polkadot/api';
import * as identityModule from '~/api/entities/Identity';
import { QueryableStorage } from '@polymathnetwork/polkadot/api/types';

describe('Context Class', () => {
describe('Context class', () => {
const mockKeyring = ImportMock.mockClass(polkadotModule, 'Keyring');
const mockApiPromise = ImportMock.mockStaticClass<polkadotModule.ApiPromise>(
const mockApiPromise = ImportMock.mockClass<polkadotModule.ApiPromise>(
polkadotModule,
'ApiPromise'
);
const mockIdentity = ImportMock.mockClass(identityModule, 'Identity');

afterAll(() => {
mockKeyring.restore();
mockApiPromise.restore();
mockIdentity.restore();
});

describe('method: create', () => {
Expand All @@ -35,11 +34,11 @@ describe('Context Class', () => {
},
});
const keyringAddFromSeedStub = mockKeyring.mock('addFromSeed', 'currentPair');
mockApiPromise.set('query', {
mockApiPromise.set('query', ({
identity: {
keyToIdentityIds: keyToIdentityIdsStub,
},
});
} as unknown) as QueryableStorage<'promise'>);

const context = await Context.create({
polymeshApi: mockApiPromise.getMockInstance(),
Expand All @@ -55,11 +54,11 @@ describe('Context Class', () => {
test('should create a Context class without Pair and Identity attached', async () => {
const keyToIdentityIdsStub = sinon.stub().returns('identityId');
const keyringAddFromSeedMock = mockKeyring.mock('addFromSeed', true);
mockApiPromise.set('query', {
mockApiPromise.set('query', ({
identity: {
keyToIdentityIds: keyToIdentityIdsStub,
},
});
} as unknown) as QueryableStorage<'promise'>);

const context = await Context.create({
polymeshApi: mockApiPromise.getMockInstance(),
Expand All @@ -76,11 +75,11 @@ describe('Context Class', () => {
unwrap: sinon.stub().throws(),
});
mockKeyring.mock('addFromSeed', 'currentPair');
mockApiPromise.set('query', {
mockApiPromise.set('query', ({
identity: {
keyToIdentityIds: keyToIdentityIdsStub,
},
});
} as unknown) as QueryableStorage<'promise'>);

const context = Context.create({
polymeshApi: mockApiPromise.getMockInstance(),
Expand Down

0 comments on commit 0ff1ae7

Please sign in to comment.