1.0.3 • Published 1 year ago

@line/liff-mock v1.0.3

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
1 year ago

LIFF Mock

LIFF Mock is a LIFF Plugin that make testing your LIFF app easy.

※ LIFF Plugin feature is available since LIFF SDK v2.19.0.

Usage

NPM

$ npm install @line/liff-mock
import liff from '@line/liff';
import { LiffMockPlugin } from '@line/liff-mock';

liff.use(new LiffMockPlugin());

liff.init({
  liffId: 'liff-xxxx',
  mock: true, // enable mock mode
});

if (!liff.isInClient()) liff.login();
const profile = await liff.getProfile();
// { displayName: 'Brown', userId: '123456789', statusMessage: 'hello' }
console.log(profile);

CDN

https://unpkg.com/@line/liff-mock@1.0.3/dist/umd/liff-mock.js

<!-- in <head> tag -->
<script src="https://unpkg.com/@line/liff-mock@1.0.3/dist/umd/liff-mock.js"></script>
const liff = window.liff;
const liffMockPlugin = window.liffMock;

liff.use(new LiffMockPlugin());

liff.init({
  liffId: 'liff-xxxx',
  mock: true, // enable mock mode
});

if (!liff.isInClient()) liff.login();
const profile = await liff.getProfile();
// { displayName: 'Brown', userId: '123456789', statusMessage: 'hello' }
console.log(profile);

API

liff.$mock.set

Set mock data

type set = (
  data: Partial<MockData> | ((prev: Partial<MockData>) => Partial<MockData>)
) => void;
const profile = await liff.getProfile();
// { displayName: 'Brown', userId: '123456789', statusMessage: 'hello' }
console.log(profile);

liff.$mock.set((p) => ({
  ...p,
  getProfile: { displayName: 'Cony', userId: '1111111' },
}));

const profile = await liff.getProfile();
// { displayName: 'Cony', userId: '1111111' }
console.log(profile);

liff.$mock.clear

Restore default mock data

type clear: () => void;
// liff.$mock.set(...)
const profile = await liff.getProfile();
// { displayName: 'Cony', userId: '1111111' }
console.log(profile);

liff.$mock.clear();

const profile = await liff.getProfile();
// { displayName: 'Brown', userId: '123456789', statusMessage: 'hello' }
console.log(profile);

Example

See examples

Contribution

$ nvm use
$ npm ci
1.0.3

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago