本文整理匯總了TypeScript中expect.assert函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript assert函數的具體用法?TypeScript assert怎麽用?TypeScript assert使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了assert函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: spyOn
spyOn(keyGen: { (x: T): any }): Spy<T> {
const targetKey = keyGen(this.nameGenerator);
assert(typeof targetKey === 'string', `${targetKey.toString()} is not valid target key`);
assert(isFunction(Reflect.get(this.mock, targetKey)), `${targetKey.toString()} is not a function`);
return this.getSpy(targetKey);
}
示例2: function
toHaveBeenCalledWithSignature: function(): void {
assert(this.actual.getLastCall(), 'spy was never called');
let lastCallArgs: Array<any> = this.actual.getLastCall().arguments;
let desiredCallArgs: Array<any> = Reflect.getMetadata(CALL_SIGNATURE_KEY, this.actual);
assert(desiredCallArgs, 'No call signature recorded');
assert(lastCallArgs.length === desiredCallArgs.length, 'Call signature mismatch; present: %s <-> desired: %s arguments', lastCallArgs.length, desiredCallArgs.length);
let mismatchIndex = -1;
let message: string;
for (let i = 0; i < lastCallArgs.length; i++) {
switch (desiredCallArgs[ i ]) {
case MATCHER.ANY:
break;
case MATCHER.STRING:
if (typeof lastCallArgs[ i ] !== 'string') {
mismatchIndex = i;
message = '%s is not a string';
}
break;
case MATCHER.NUMBER:
if (typeof lastCallArgs[ i ] !== 'number') {
mismatchIndex = i;
message = '%s is not a number';
}
break;
case MATCHER.OBJECT:
if (typeof lastCallArgs[ i ] !== 'object') {
mismatchIndex = i;
message = '%s is not an object';
}
break;
case MATCHER.ARRAY:
if (!Array.isArray(lastCallArgs[ i ])) {
mismatchIndex = i;
message = '%s is not an array';
}
break;
default:
if (!isEqual(lastCallArgs[ i ], desiredCallArgs[ i ])) {
mismatchIndex = i;
message = 'Arguments mismatch; present: %s <-> desired: %s at position %s';
}
}
assert(mismatchIndex === -1, message, lastCallArgs[ mismatchIndex ], desiredCallArgs[ mismatchIndex ], mismatchIndex);
}
}
示例3: getter
get: function getter() {
assert(isFunction(Reflect.getMetadata(VALUE_KEY, _this.mock, property)), `${property.toString()} is not a function`);
return (...args: Array<any>) => {
Reflect.defineMetadata(CALL_SIGNATURE_KEY, args, _this.getSpy(property));
return property;
};
}
示例4: toHaveBeenCalledWithSignature
import isEqual from 'is-equal';
import { Extension, assert } from 'expect';
import { MATCHER } from './It';
import { CALL_SIGNATURE_KEY } from '../mock/MetaKeys';
export const expectExtensions: Extension = {
toHaveBeenCalledWithSignature(): void {
assert(this.actual.getLastCall(), 'spy was never called');
let lastCallArgs: Array<any> = this.actual.getLastCall().arguments;
let desiredCallArgs: Array<any> = Reflect.getMetadata(CALL_SIGNATURE_KEY, this.actual);
assert(desiredCallArgs != null, 'No call signature recorded');
assert(lastCallArgs.length === desiredCallArgs.length, 'Call signature mismatch; present: %s <-> desired: %s arguments', lastCallArgs.length, desiredCallArgs.length);
let mismatchIndex = -1;
let message: string;
for (let i = 0; i < lastCallArgs.length; i++) {
switch (desiredCallArgs[i]) {
case MATCHER.ANY:
break;
case MATCHER.STRING:
if (typeof lastCallArgs[i] !== 'string') {
mismatchIndex = i;
message = '%s is not a string';
}
break;
case MATCHER.NUMBER:
if (typeof lastCallArgs[i] !== 'number') {
mismatchIndex = i;
示例5: assert
return fetchPromise.then(()=> {
assert(store && store.model && (store.model.value === model.value), `model should be properly defined after load`);
assert(fetchSpy.calls.length === 1, 'there should be exactly one fetch');
assert(fetchSpy.calls[0].arguments.length === 1, 'fetch should get url as paramter');
});
示例6: require
import MonthSelectMock from "../helper/MonthSelectMock";
import ExpensesMock from "../../Expenses/ExpensesMock";
let createDocument = require('../helper/createDocument');
createDocument['default']();
let assert = require('assert');
//import expect, { createSpy, spyOn, isSpy } from 'expect';
let expect = require('expect');
require('../src/Util/Number'); // for clamp
expect.extend( {
toBeAColor() {
expect.assert(
this.actual.match(/^#[a-fA-F0-9]{3,6}$/),
'expected %s to be an HTML color',
this.actual
);
return this;
},
toBeSameTime(time: Date) {
expect.assert(
this.actual.getTime() == time.getTime(),
'expected %s to be the same time\n'+
this.actual.getTime() + ' != ' + time.getTime()+'\n'+
this.actual.toString('yyyy-MM-dd HH:mm:ss') + ' != ' + time.toString('yyyy-MM-dd HH:mm:ss'),
this.actual
);
return this;
}