### Development Setup
Source: https://github.com/line/liff-mock/blob/main/README.md
Set up your development environment by installing Node.js version manager and installing project dependencies.
```sh
$ nvm use
$ npm ci
```
--------------------------------
### Install LIFF Mock via NPM
Source: https://github.com/line/liff-mock/blob/main/README.md
Install the LIFF Mock plugin using npm. This is the recommended method for Node.js environments.
```sh
$ npm install @line/liff-mock
```
--------------------------------
### Initialize LIFF with Mock Plugin and Pluggable SDK (NPM)
Source: https://github.com/line/liff-mock/blob/main/README.md
When using LIFF Mock with the Pluggable SDK, install `IsInClientModule` before `LiffMockPlugin` as LIFF Mock depends on `liff.isInClient`.
```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);
```
--------------------------------
### Initialize LIFF with Mock Plugin (CDN)
Source: https://github.com/line/liff-mock/blob/main/README.md
After including the script via CDN, initialize LIFF with the mock plugin enabled. Access LIFF and the mock plugin through the `window` object.
```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);
```
--------------------------------
### Initialize LIFF with Mock Plugin (NPM)
Source: https://github.com/line/liff-mock/blob/main/README.md
Integrate the LIFF Mock plugin into your LIFF application by importing and using it with `liff.use()`. Ensure mock mode is enabled during initialization.
```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);
```
--------------------------------
### Include LIFF Mock via CDN
Source: https://github.com/line/liff-mock/blob/main/README.md
Include the LIFF Mock script in your HTML file using a CDN link. This makes the LIFF and LIFF Mock objects available globally.
```html
```
--------------------------------
### liff.$mock.clear
Source: https://github.com/line/liff-mock/blob/main/README.md
Restores the default mock data for LIFF SDK methods, effectively resetting the mock environment to its initial state.
```APIDOC
## liff.$mock.clear
### Description
Restores the default mock data for LIFF SDK methods, effectively resetting the mock environment to its initial state.
### Method Signature
```typescript
type clear: () => void;
```
### Usage Example
```javascript
// Assume mock data has been set previously using liff.$mock.set
// Clear all mock data to restore default behavior
liff.$mock.clear();
// Subsequent calls to LIFF SDK methods will now use the default mock data or actual LIFF client behavior if not in mock mode
const profile = await liff.getProfile();
// Expected output (default mock): { displayName: 'Brown', userId: '123456789', statusMessage: 'hello' }
console.log(profile);
```
```
--------------------------------
### liff.$mock.set
Source: https://github.com/line/liff-mock/blob/main/README.md
Sets mock data for LIFF SDK methods. This function can accept a partial MockData object or a function that receives the previous mock data and returns the updated data.
```APIDOC
## liff.$mock.set
### Description
Sets mock data for LIFF SDK methods. This function can accept a partial MockData object or a function that receives the previous mock data and returns the updated data.
### Method Signature
```typescript
type set = (
data: Partial | ((prev: Partial) => Partial)
) => void;
```
### Usage Example
```javascript
// Example of setting mock data for getProfile
liff.$mock.set((p) => ({
...p,
getProfile: { displayName: 'Cony', userId: '1111111' },
}));
// After setting mock data, subsequent calls to liff.getProfile() will return the mocked data
const profile = await liff.getProfile();
// Expected output: { displayName: 'Cony', userId: '1111111' }
console.log(profile);
```
```
--------------------------------
### Set Mock Data for LIFF API
Source: https://github.com/line/liff-mock/blob/main/README.md
Use `liff.$mock.set()` to define custom mock data for LIFF API calls. This function accepts an object or a function that receives the previous mock data.
```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);
```
--------------------------------
### Clear Mock Data
Source: https://github.com/line/liff-mock/blob/main/README.md
Call `liff.$mock.clear()` to reset all mock data and restore the default mock behavior of the LIFF Mock plugin.
```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);
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.