vitest#expect TypeScript Examples
The following examples show how to use
vitest#expect.
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: markdown-image-parsing.test.ts From obsidian-imgur-plugin with MIT License | 6 votes |
describe("isWrapped type predicate", () => {
it("treats simple image as not-wrapped", () => {
const matchedPieces = findImgurMarkdownImage(
"![](https://i.imgur.com/m3RpPCV.png)",
0
).mdImagePieces;
expect(isWrapped(matchedPieces)).toBeFalsy();
});
it("correctly detects wrapped image", () => {
const matchedPieces = findImgurMarkdownImage(
"[![](https://i.imgur.com/m3RpPCVs.png)](https://i.imgur.com/m3RpPCV.png)",
0
).mdImagePieces;
expect(isWrapped(matchedPieces)).toBeTruthy();
});
});
Example #5
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 #6
Source File: defineTypeCheck.ts From volar with MIT License | 6 votes |
export function defineTypeCheck(fileName: string) {
describe(`type check to ${path.relative(volarRoot, fileName)}`, () => {
const uri = shared.fsPathToUri(fileName);
const script = tester.host.getScriptSnapshot(fileName);
let errors: vscode.Diagnostic[] | undefined;
beforeAll(async () => {
errors = await tester.languageService.doValidation(uri);
});
it(`should has script snapshot`, async () => {
expect(!!script).toEqual(true);
});
it(`should has 0 errors`, async () => {
if (errors?.length) {
console.log(errors);
}
expect(errors?.length).toEqual(0);
});
});
}
Example #7
Source File: processDatabase.test.ts From kanel with MIT License | 6 votes |
describe('processDatabase', () => {
it('should process the dvd rental example according to the snapshot', async () => {
await processDatabase({
connection: {},
preDeleteModelFolder: false,
customTypeMap: {
tsvector: {
name: 'TsVector',
module: 'ts-vector',
absoluteImport: true,
defaultImport: true,
},
bpchar: 'string',
},
resolveViews: true,
schemas: [
{
name: 'public',
modelFolder: '/models',
ignore: ['film_list', 'staff'],
},
],
});
// @ts-ignore
const results = writeFile.mock.calls;
expect(results).toMatchSnapshot();
});
});
Example #8
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 #9
Source File: parse-public-key.spec.ts From cloud-cryptographic-wallet with MIT License | 6 votes |
describe("parsePublicKey", () => {
it("should be parse (AWS KMS)", () => {
const bytes = Bytes.fromString(
"3056301006072a8648ce3d020106052b8104000a034200046ce651c2445abd0915d97b683ff35cc6de4c340b8759918fd34cacf4395c39b0e2ad7517c9ab585ed5213ef0c00a1896f390eb03ff1ef8a13e18f036fa62a9e4"
);
const publicKey = parsePublicKey(bytes.buffer);
const expected = Address.fromBytes(
Bytes.fromString("0b45ff0aea02cb12b8923743ecebc83fe437c614")
);
expect(
expected.equals(
PublicKey.fromBytes(Bytes.fromArrayBuffer(publicKey)).toAddress()
)
);
});
it("should be parse (Cloud KMS)", () => {
const bytes = Bytes.fromString(
"3056301006072a8648ce3d020106052b8104000a03420004d4f664a42f91df474e4e97549f773a187ed85f93af9fc4053a29961d9c810ea33c8894a313631c7eee83916ef32ad5dbc321f06b1d600f039eee22488d6b48d1"
);
const publicKey = parsePublicKey(bytes.buffer);
const expected = Address.fromBytes(
Bytes.fromString("0x9f60980a13f74d79214e258d2f52fd846a3a5511")
);
expect(
expected.equals(
PublicKey.fromBytes(Bytes.fromArrayBuffer(publicKey)).toAddress()
)
);
});
});
Example #10
Source File: normalize-url.test.ts From osmosfeed with MIT License | 6 votes |
describe("normalizeUrl", () => {
it("handles url that doesn't need encoding", async () => {
await expect(normalizeUrl("https://www.mockdomain.com")).toEqual("https://www.mockdomain.com");
});
it("handles url that needs encoding", async () => {
await expect(normalizeUrl("https://www.mockdomain.com/hello world")).toEqual(
"https://www.mockdomain.com/hello%20world"
);
});
it("handles url that is encoded", async () => {
await expect(normalizeUrl("https://www.mockdomain.com/hello%20world")).toEqual(
"https://www.mockdomain.com/hello%20world"
);
});
it("handles url unicode characters", async () => {
await expect(normalizeUrl("https://www.你好.com?query=世界")).toEqual(
"https://www.%E4%BD%A0%E5%A5%BD.com?query=%E4%B8%96%E7%95%8C"
);
});
});
Example #11
Source File: VPerfectSignature.test.ts From v-perfect-signature with MIT License | 6 votes |
describe('#props', () => {
it('should receive default props', () => {
const wrapper = shallowMount(VPerfectSignature)
const expectedWidth = '100%'
const expectedHeight = '100%'
const expectedPenColor = '#000'
const expectedBackgroundColor = 'rgba(0,0,0,0)'
const expectedStrokeOptions = {}
expect(wrapper.props().width).toBe(expectedWidth)
expect(wrapper.props().height).toBe(expectedHeight)
expect(wrapper.props().penColor).toBe(expectedPenColor)
expect(wrapper.props().backgroundColor).toBe(expectedBackgroundColor)
expect(wrapper.props().strokeOptions).toEqual(expectedStrokeOptions)
})
})
Example #12
Source File: config.test.ts From d3-graph-controller with MIT License | 5 votes |
describe.concurrent('Config', () => {
describe('can be defined', () => {
it('using default values', () => {
const config = defineGraphConfig()
expect(config).toMatchSnapshot()
})
it('with deep merging', () => {
const defaultConfig = defineGraphConfig()
const customConfig = defineGraphConfig({
simulation: {
forces: {
collision: {
radiusMultiplier: 42,
},
},
},
})
const customCollisionForce = customConfig.simulation.forces.collision
expect(customCollisionForce).not.toBe(false)
// @ts-expect-error It has been asserted that the force is not false
expect(customCollisionForce.radiusMultiplier).toEqual(42)
expect(customConfig).not.toEqual(defaultConfig)
const customMerge = {
...defaultConfig,
simulation: {
...defaultConfig.simulation,
forces: {
...defaultConfig.simulation.forces,
collision: {
...defaultConfig.simulation.forces.collision,
radiusMultiplier: 42,
},
},
},
}
expect(customMerge.simulation.forces).toStrictEqual(
customConfig.simulation.forces
)
})
})
})
Example #13
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 #14
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 #15
Source File: index.test.ts From reskript with MIT License | 5 votes |
testFixture = (name: string, shouldInject: boolean) => {
const filename = path.join(dirFromImportMeta(import.meta.url), 'fixtures', name);
const content = fs.readFileSync(filename, 'utf-8');
const result = babel.transformSync(content, {...BABEL_OPTIONS, filename});
expect((result?.code ?? '').includes('useComponentFile("')).toBe(shouldInject);
expect((result?.code ?? '').includes(`import useComponentFile from "${HOOK_MODULE}"`)).toBe(shouldInject);
}
Example #16
Source File: markdown-image-parsing.test.ts From obsidian-imgur-plugin with MIT License | 5 votes |
describe("findImgurMarkdownImage", () => {
const simplestImage = "![](https://i.imgur.com/m3RpPCV.png)";
it.each([
{ line: simplestImage, cursorAt: 0 },
{ line: simplestImage, cursorAt: 35 },
{ line: "![](https://i.imgur.com/m3RpPCVm.png)", cursorAt: 0 },
])("GIVEN line '$line' and cursor pos: $cursorAt", ({ line, cursorAt }) => {
const match = findImgurMarkdownImage(line, cursorAt);
expect(match.exists).toBeTruthy();
});
it("matches an image when cursor position is set to last character of image", () => {
const match = findImgurMarkdownImage(simplestImage, 35);
expect(match.exists).toBeTruthy();
});
it("does not match an image when cursor position is after an image", () => {
const match = findImgurMarkdownImage(simplestImage, 36);
expect(match.exists).toBeFalsy();
});
it("matches 2nd image when cursor is between the 1st and second one", () => {
const match = findImgurMarkdownImage(
"![](https://i.imgur.com/m3RpPCV.png)![](https://i.imgur.com/pLIMYhw.png)",
36
);
expect(match.exists).toBeTruthy();
expect(match.mdImagePieces.imageId).toBe("pLIMYhw");
});
it("throws error for images with unexpected length of image id", () => {
it.each([
{ line: "![](https://i.imgur.com/m3RpPCVsm.png)" },
{ line: "![](https://i.imgur.com/m3RpPC.png)" },
])(
"GIVEN line '$line' an error reporting incorrect image id size will be thrown",
({ line }) => {
const match = findImgurMarkdownImage(line, 0);
expect(match.mdImagePieces).toThrowError();
}
);
});
});
Example #17
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);
});