2.3.2 • Published 4 years ago

@vkontakte/vk-connect-mock v2.3.2

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

VK Connect Mock npm Build Status

This library mocks VK Connect methods.

Usage

Install the library via yarn

$ yarn add @vkontakte/vk-connect-mock

or npm

$ npm install @vkontakte/vk-connect-mock

Use in your code instead of using vk-connect by following way:

import vkConnect from '@vkontakte/vk-connect-mock';

vkConnect.sendPromise('VKWebAppGetUserInfo', {}).then(data => {
  // Do something
});

Or event-based way:

import vkConnect from '@vkontakte/vk-connect-mock';

vkConnect.subscribe(e => {
  if (e.detail.type === 'VKWebAppGetUserInfoResult') {
    // Do something
  }
});

vkConnect.send('VKWebAppGetUserInfo', {});

Please note that some methods may only receive (for example, VKWebAppUpdateConfig, VKWebAppViewHide, VKWebAppViewRestore, etc.). To obtain data from them you need to use the event-based way and callReceiveOnlyMethod()

import vkConnect, { callReceiveOnlyMethod } from '@vkontakte/vk-connect-mock';

vkConnect.subscribe(e => {
  if (e.detail.type === 'VKWebAppUpdateConfig') {
    // Do something
  }
});

// Use this function when you need to get data
callReceiveOnlyMethod('VKWebAppUpdateConfig');

More documentation regarding VK Connect is here.

Using with VK Mini Apps API

You can also use this library in conjunction with VK Mini Apps API:

import { VKMiniAppAPI } from '@vkontakte/vk-mini-apps-api';
import vkConnectMock from '@vkontakte/vk-connect-mock';

// Creating API instance
const api = new VKMiniAppAPI(vkConnectMock);

// Using methods
api.getUserInfo().then(userInfo => {
  // Do something with mock data of user info
});
2.3.0

4 years ago

2.2.0

4 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.1.0

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

5 years ago

2.0.0

5 years ago

2.0.0-beta.1

5 years ago

2.0.0-beta

5 years ago