當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript expect.assert函數代碼示例

本文整理匯總了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);
  }
開發者ID:donaldpipowitch,項目名稱:emock,代碼行數:8,代碼來源:Mock.ts

示例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);
    }
  }
開發者ID:ManuCutillas,項目名稱:emock,代碼行數:50,代碼來源:ExpectExtensions.ts

示例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;
          };
        }
開發者ID:donaldpipowitch,項目名稱:emock,代碼行數:8,代碼來源:Mock.ts

示例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;
開發者ID:donaldpipowitch,項目名稱:emock,代碼行數:31,代碼來源:ExpectExtensions.ts

示例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');
 });
開發者ID:DJCordhose,項目名稱:flow-vs-typescript,代碼行數:5,代碼來源:load.spec.ts

示例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;
	}
開發者ID:spidgorny,項目名稱:umsaetze,代碼行數:31,代碼來源:MonthSelect.test.ts


注:本文中的expect.assert函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。