Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/line/liff-mock
LIFF Mock is a LIFF Plugin that make testing your LIFF app easy.
https://github.com/line/liff-mock
liff liff-plugin liff-sdk line mock test
Last synced: about 2 months ago
JSON representation
LIFF Mock is a LIFF Plugin that make testing your LIFF app easy.
- Host: GitHub
- URL: https://github.com/line/liff-mock
- Owner: line
- License: apache-2.0
- Created: 2022-04-14T01:42:27.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-02T01:12:52.000Z (12 months ago)
- Last Synced: 2024-06-12T14:16:11.091Z (3 months ago)
- Topics: liff, liff-plugin, liff-sdk, line, mock, test
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@line/liff-mock
- Size: 216 KB
- Stars: 34
- Watchers: 7
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# 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
```sh
$ npm install @line/liff-mock
``````ts
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);
```### With [Pluggable SDK](https://developers.line.biz/en/docs/liff/pluggable-sdk/)
If you use LIFF Mock with Pluggable SDK mode, you have to install `IsInClientModule` before the installation of `LiffMockPlugin` because LIFF Mock depends on `liff.isInClient` API.
```ts
import liff from '@line/liff/core';
import IsInClientModule from "@line/liff/is-in-client";
import { LiffMockPlugin } from '@line/liff-mock';liff.use(new IsInClientModule()); // <-- Please install IsInClientModule before LiffMockPlugin
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/[email protected]/dist/umd/liff-mock.js
```html
```
```js
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
```ts
type set = (
data: Partial | ((prev: Partial) => Partial)
) => void;
``````js
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
```ts
type clear: () => void;
``````js
// 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](./examples)
# Contribution
```sh
$ nvm use
$ npm ci
```