UNPKG

@koralabs/cardano-wallets

Version:

Library for connecting cardano wallets in the browser using CIP-30

75 lines (74 loc) 3.1 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const _1 = require("."); describe('CardanoWallets Tests', () => { describe('connect Tests', () => { it('Should throw error if window is not defined', () => __awaiter(void 0, void 0, void 0, function* () { try { yield _1.CardanoWallets.connect('nami'); } catch (error) { expect(error.message).toEqual('window is not defined'); } })); it('Should throw error if window.cardano is not defined', () => __awaiter(void 0, void 0, void 0, function* () { // @ts-ignore global.window = {}; try { yield _1.CardanoWallets.connect('nami'); } catch (error) { expect(error.message).toEqual('No wallets found'); } })); it('Should throw error if window.cardano.nami is not defined', () => __awaiter(void 0, void 0, void 0, function* () { // @ts-ignore global.window = { cardano: { eternl: {} } }; try { yield _1.CardanoWallets.connect('nami'); } catch (error) { expect(error.message).toEqual('Specific wallet not found'); } })); it('Should connect and save wallet details', () => __awaiter(void 0, void 0, void 0, function* () { // @ts-ignore global.window = { // @ts-ignore localStorage: { setItem: jest.fn(), getItem: jest.fn() }, cardano: { nami: { icon: 'some-icon.jpg', name: 'Nami', enable: () => jest.fn(), isEnabled: () => true } } }; yield _1.CardanoWallets.connect('nami'); expect(_1.CardanoWallets.wallet.name).toEqual('Nami'); })); }); describe('buildUtxos tests', () => { it('Should build it', () => __awaiter(void 0, void 0, void 0, function* () { const result = yield _1.CardanoWallets.buildUtxos(['test1', 'test2']); expect(result).toEqual(null); })); }); });