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


TypeScript expect.extend函數代碼示例

本文整理匯總了TypeScript中expect.extend函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript extend函數的具體用法?TypeScript extend怎麽用?TypeScript extend使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了extend函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

  jasmine.addMatchers = (jasmineMatchersObject: JasmineMatchersObject) => {
    const jestMatchersObject = Object.create(null);
    Object.keys(jasmineMatchersObject).forEach(name => {
      jestMatchersObject[name] = function(
        this: MatcherState,
        ...args: Array<unknown>
      ): RawMatcherFn {
        // use "expect.extend" if you need to use equality testers (via this.equal)
        const result = jasmineMatchersObject[name](null, null);
        // if there is no 'negativeCompare', both should be handled by `compare`
        const negativeCompare = result.negativeCompare || result.compare;

        return this.isNot
          ? negativeCompare.apply(
              null,
              // @ts-ignore
              args,
            )
          : result.compare.apply(
              null,
              // @ts-ignore
              args,
            );
      };
    });

    const expect = global.expect;
    expect.extend(jestMatchersObject);
  };
開發者ID:Volune,項目名稱:jest,代碼行數:29,代碼來源:jestExpect.ts

示例2: default

export default (config: {expand: boolean}) => {
  global.expect = expect;
  expect.setState({
    expand: config.expand,
  });
  expect.extend({
    toMatchInlineSnapshot,
    toMatchSnapshot,
    toThrowErrorMatchingInlineSnapshot,
    toThrowErrorMatchingSnapshot,
  });

  expect.addSnapshotSerializer = addSerializer;
};
開發者ID:Volune,項目名稱:jest,代碼行數:14,代碼來源:jestExpect.ts

示例3: default

export default (config: {expand: boolean}) => {
  global.expect = expect;
  expect.setState({expand: config.expand});
  expect.extend({
    toMatchInlineSnapshot,
    toMatchSnapshot,
    toThrowErrorMatchingInlineSnapshot,
    toThrowErrorMatchingSnapshot,
  });
  expect.addSnapshotSerializer = addSerializer;

  const jasmine = global.jasmine as Jasmine;
  jasmine.anything = expect.anything;
  jasmine.any = expect.any;
  jasmine.objectContaining = expect.objectContaining;
  jasmine.arrayContaining = expect.arrayContaining;
  jasmine.stringMatching = expect.stringMatching;

  jasmine.addMatchers = (jasmineMatchersObject: JasmineMatchersObject) => {
    const jestMatchersObject = Object.create(null);
    Object.keys(jasmineMatchersObject).forEach(name => {
      jestMatchersObject[name] = function(
        this: MatcherState,
        ...args: Array<unknown>
      ): RawMatcherFn {
        // use "expect.extend" if you need to use equality testers (via this.equal)
        const result = jasmineMatchersObject[name](null, null);
        // if there is no 'negativeCompare', both should be handled by `compare`
        const negativeCompare = result.negativeCompare || result.compare;

        return this.isNot
          ? negativeCompare.apply(
              null,
              // @ts-ignore
              args,
            )
          : result.compare.apply(
              null,
              // @ts-ignore
              args,
            );
      };
    });

    const expect = global.expect;
    expect.extend(jestMatchersObject);
  };
};
開發者ID:Volune,項目名稱:jest,代碼行數:48,代碼來源:jestExpect.ts

示例4: Adapter

// declare var babelHelpers: any
// Object.assign(babelHelpers, { applyDecoratedDescriptor, initializerDefineProperty })
// import "@babel/runtime"

import chalk from "chalk"
import Enzyme from "enzyme"
import Adapter from "enzyme-adapter-react-16"
import expect from "expect"
import { format } from "util"

import "lib/tests/renderUntil"
Enzyme.configure({ adapter: new Adapter() })

// Waiting on https://github.com/thymikee/snapshot-diff/pull/17
import diff from "snapshot-diff"
expect.extend({ toMatchDiffSnapshot: (diff as any).toMatchDiffSnapshot })

jest.mock("react-tracking")
import _track from "react-tracking"
const track = _track as jest.Mock<typeof _track>
track.mockImplementation((_ => x => x) as any)

// Mock this separately so react-tracking can be unmocked in tests but not result in the `window` global being accessed.
jest.mock("react-tracking/build/dispatchTrackingEvent")

jest.mock("./lib/NativeModules/NotificationsManager.tsx", () => ({
  NotificationsManager: {
    addListener: jest.fn(),
  },
}))
開發者ID:artsy,項目名稱:emission,代碼行數:30,代碼來源:setupJest.ts

示例5: extend

import { Mock } from '../src/mock/Mock';
import expect, { extend } from 'expect';
import { It } from '../src/utils/It';
import { expectExtensions } from '../src/utils/ExpectExtensions';

extend(expectExtensions);

class MyService {
  testProperty: number;

  simple() {
    return true;
  }

  multipleArguments(any: any, string: string, number: number, obj: Object) {
    return true;
  }
}

class MyServiceExtended extends MyService {
  simpleString(s: string) {
    return true;
  }

  simpleNumber(s: number) {
    return true;
  }

  simpleObject(s: Object) {
    return true;
  }
開發者ID:otbe,項目名稱:emock,代碼行數:31,代碼來源:Mock.ts

示例6: require

import * as mocha from 'mocha';
import { fromJS } from 'immutable';
//import * as expect from 'expect'; // doesn't work
var expect = require('expect');
import expectImmutable from 'expect-immutable';
expect.extend(expectImmutable);

import { LOGIN_SUCCESS, LOGOUT_SUCCESS } from './SessionActions';
import SessionReducer from './SessionReducer';

describe("SessionReducer", () => {
	context("with a user logged in", () => {
		const state = fromJS({ userId: 'pdavis', displayName: 'Phil' });

		it("can log in a different user", () => {
			const action = { type: LOGIN_SUCCESS, payload: { userId: 'jdavis', displayName: 'Jen' } };
			expect(SessionReducer(state, action)).toEqualImmutable(fromJS({ userId: 'jdavis', displayName: 'Jen' }));
		});

		it("can log out the user", () => {
			const action = { type: LOGOUT_SUCCESS, payload: {} };
			expect(SessionReducer(state, action)).toEqualImmutable(fromJS({}));
		});

		it("can register a new user but won't log them in"); // TODO // and todo permissions checking
	});

	context("with nobody logged in", () => {
		const state = fromJS({});

		it("can log in a user", () => {
開發者ID:PhilipDavis,項目名稱:react-redux,代碼行數:31,代碼來源:SessionReducer_spec.ts

示例7: require

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;
	}
});

class MonthSelectTest {

	/**
	 * constructor should make an object
開發者ID:spidgorny,項目名稱:umsaetze,代碼行數:31,代碼來源:MonthSelect.test.ts


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