vitest#test TypeScript Examples
The following examples show how to use
vitest#test.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.test.ts From reskript with MIT License | 7 votes |
describe('addHotModuleToEntry', () => {
test('string entry', async () => {
const entry = await addHotModuleToEntry('src/index.js', process.cwd()) as string[];
expect(Array.isArray(entry)).toBe(true);
expect(entry.some(v => v.includes('webpack/hot/dev-server.js'))).toBe(true);
expect(entry.some(v => v.includes('webpack-dev-server/client/index.js'))).toBe(true);
});
test('object entry', async () => {
const entry = await addHotModuleToEntry({import: 'src/index.js'}, process.cwd()) as EntryDescription;
expect(entry.import).toBeTruthy();
const imports = entry.import as string[];
expect(Array.isArray(imports)).toBe(true);
expect(imports.some(v => v.includes('webpack/hot/dev-server.js'))).toBe(true);
expect(imports.some(v => v.includes('webpack-dev-server/client/index.js'))).toBe(true);
});
});
Example #2
Source File: contract.test.ts From ethcall with MIT License | 6 votes |
describe('Contract', () => {
test('inits a contract', () => {
const address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
const contract = new Contract(address, erc20Abi);
expect(contract.address).toEqual(address);
expect(contract.abi).toEqual(erc20Abi);
});
test('creates a call', () => {
const address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
const contract = new Contract(address, erc20Abi);
const ownerCall = contract.name() as Call;
expect(ownerCall.contract.address).toEqual(address);
expect(ownerCall.name).toEqual('name');
});
});
Example #3
Source File: index.test.ts From reskript with MIT License | 6 votes |
runSuite = createTestRunner(
dirFromImportMeta(import.meta.url),
{test, expect},
{
presets: [
'@babel/preset-react',
],
plugins: [plugin],
}
)
Example #4
Source File: index.test.ts From icepkg with MIT License | 6 votes |
test('getUnpkgHost custom host', () => {
const custom = 'https://unpkg.example.com';
process.env.UNPKG = custom;
expect(getUnpkgHost('koa')).toBe(custom);
expect(getUnpkgHost('@ali/ice-test')).toBe(custom);
delete process.env.UNPKG;
});
Example #5
Source File: createMindmap.test.ts From remind with MIT License | 6 votes |
test('should render value', async () => {
const editorInstance: RefObject<ContributionAPI> = createMindmap(container, {
value: root,
})
expect(editorInstance.current?.model.root).equal(root)
expect(
editorInstance.current?.view.current?.innerHTML.includes(root.title),
).toBeTruthy()
})
Example #6
Source File: get-accounts.spec.ts From cloud-cryptographic-wallet with MIT License | 6 votes |
test("get addresses", async () => {
const signers = [new SignerForTest(), new SignerForTest()];
const addresses = await getAccounts(signers);
expect(addresses[0]).toBe(
(await signers[0].getPublicKey()).toAddress().toString()
);
expect(addresses[1]).toBe(
(await signers[1].getPublicKey()).toAddress().toString()
);
});
Example #7
Source File: abi.test.ts From ethcall with MIT License | 5 votes |
describe('ABI', () => {
test('encodes input', () => {
expect(Abi.encode(ownerFunction.name, ownerFunction.inputs, [])).toEqual(
'0x8da5cb5b',
);
expect(
Abi.encode(balanceOfFunction.name, balanceOfFunction.inputs, [
'0x1a9c8182c09f50c8318d769245bea52c32be35bc',
]),
).toEqual(
'0x70a082310000000000000000000000001a9c8182c09f50c8318d769245bea52c32be35bc',
);
expect(
Abi.encode(swapFunction.name, swapFunction.inputs, [
{
inAmount: '250000000',
inAsset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
outAsset: '0x6b175474e89094c44da98b954eedeac495271d0f',
},
'1633000000',
]),
).toEqual(
'0xa18d33e1000000000000000000000000000000000000000000000000000000000ee6b280000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000061559a40',
);
});
test('encodes constructor input', () => {
expect(Abi.encodeConstructor(ownerFunction.inputs, [])).toEqual('0x');
expect(
Abi.encodeConstructor(balanceOfFunction.inputs, [
'0x1a9c8182c09f50c8318d769245bea52c32be35bc',
]),
).toEqual(
'0x0000000000000000000000001a9c8182c09f50c8318d769245bea52c32be35bc',
);
expect(
Abi.encodeConstructor(swapFunction.inputs, [
{
inAmount: '250000000',
inAsset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
outAsset: '0x6b175474e89094c44da98b954eedeac495271d0f',
},
'1633000000',
]),
).toEqual(
'0x000000000000000000000000000000000000000000000000000000000ee6b280000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000061559a40',
);
});
test('decodes output', () => {
expect(
Abi.decode(
ownerFunction.name,
ownerFunction.outputs,
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
),
).toEqual(['0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48']);
expect(
Abi.decode(
balanceOfFunction.name,
balanceOfFunction.outputs,
'0x000000000000000000000000000000000000000000000000bb59a27953c60000',
).map((a) => a.toString()),
).toEqual(['13500000000000000000']);
expect(Abi.decode(swapFunction.name, swapFunction.outputs, '0x')).toEqual(
[],
);
});
});
Example #8
Source File: index.test.ts From carbon-pictograms-svelte with Apache License 2.0 | 5 votes |
test("Library has 0 dependencies", () => {
// @ts-expect-error
expect(Object.keys(pkg.dependencies ?? {}).length).toEqual(0);
});
Example #9
Source File: index.test.ts From reskript with MIT License | 5 votes |
test('export default component', () => testFixture('src/export-default-component.js', true));
Example #10
Source File: index.test.ts From icepkg with MIT License | 5 votes |
test('getNpmRegistry', () => {
expect(tbRegisties.includes(getNpmRegistry('koa'))).toBeTruthy();
expect(tbRegisties.includes(getNpmRegistry('@alixxx/ice-test'))).toBeTruthy();
expect(getNpmRegistry('@ali/ice-test')).toBe(ALI_NPM_REGISTRY);
expect(getNpmRegistry('@alife/ice-test')).toBe(ALI_NPM_REGISTRY);
expect(getNpmRegistry('@alipay/ice-test')).toBe(ALI_NPM_REGISTRY);
});
Example #11
Source File: createMindmap.test.ts From remind with MIT License | 5 votes |
test('should render mindmap', async () => {
const editorInstance: RefObject<ContributionAPI> = createMindmap(container)
expect(types.isMindmap(editorInstance.current?.view.current)).toBe(true)
})
Example #12
Source File: lookup-signer.spec.ts From cloud-cryptographic-wallet with MIT License | 5 votes |
test("lookup signer", async () => {
const address = (await signers[2].getPublicKey()).toAddress().toString();
const signer = await lookupSigner(address, signers);
expect(signer).toEqual(signers[2]);
});