@hadronous/pic v0.8.1
Pic JS
Pic JS is a library for interacting with a local instance of pocket-ic
from TypeScript.
The pocket-ic
is a canister testing platform for the Internet Computer. It is a standalone executable that can be used to test canisters locally, without the need to deploy them to a full replica.
Other languages available include Python and Rust.
Installation
npm i -D @hadronous/pic
Usage
The easist way to use PocketIC is to use setupCanister
convenience method:
import { PocketIc } from '@hadronous/pic';
import { _SERVICE, idlFactory } from '../declarations';
const wasmPath = resolve('..', '..', 'canister.wasm');
const pic = await PocketIc.create();
const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
const { actor } = fixture;
// perform tests...
await pic.tearDown();
If more control is needed, then the createCanister
, installCode
and createActor
methods can be used directly:
import { PocketIc } from '@hadronous/pic';
import { _SERVICE, idlFactory } from '../declarations';
const wasmPath = resolve('..', '..', 'canister.wasm');
const pic = await PocketIc.create();
const canisterId = await pic.createCanister();
await pic.installCode(canisterId, wasmPath);
const actor = pic.createActor<_SERVICE>(idlFactory, canisterId);
// perform tests...
await pic.tearDown();
API Docs
More detailed documentation is available in the API docs. The best place to start is with the PocketIc class and then move onto the Actor class.
Examples
All examples are written in TypeScript with Jest as the test runner,
but @hadronous/pic
can be used with JavaScript and any other testing runner, such as NodeJS, bun or Mocha.
7 days ago
16 days ago
16 days ago
16 days ago
21 days ago
22 days ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago