本文整理汇总了TypeScript中chai.use函数的典型用法代码示例。如果您正苦于以下问题:TypeScript use函数的具体用法?TypeScript use怎么用?TypeScript use使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了use函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as sinon from 'sinon';
import * as sinonChai from 'sinon-chai';
import {
PrecedenceOptions,
requireScopesMiddleware,
ScopeMiddlewareOptions
} from '../../../src';
import { Response, Request } from 'express';
chai.use(chaiAsPromised);
chai.use(sinonChai);
const expect = chai.expect;
describe('express tooling', () => {
const loggerMock = undefined;
const createRequestMock = (scopes: String[]): Request => ({
get: (name: string) => name,
$$tokeninfo: {
scope: scopes
}
} as any as Request);
const createResponseMock = (): Response => ({
sendStatus: sinon.spy((status: string) => undefined)
} as any as Response);
示例2: use
import 'reflect-metadata';
import {expect, use} from 'chai';
import { createStore } from 'redux';
import {NgRedux} from '../../components/ng-redux';
import {select} from '../../decorators/select';
import * as sinon from 'sinon';
import * as sinonChai from 'sinon-chai';
import * as _ from 'lodash';
use(sinonChai);
describe('@select', () => {
let ngRedux;
let targetObj;
let defaultState;
let rootReducer;
let mockAppRef;
beforeEach(() => {
defaultState = {
foo: 'bar',
baz: -1
};
rootReducer = (state = defaultState, action) => {
const newState = Object.assign({}, state, { baz: action.payload });
return newState;
};
targetObj = {};
mockAppRef = {
tick: sinon.spy()
示例3: getStateFlagName
import * as chai from 'chai';
import * as sinonChai from 'sinon-chai';
import { State } from '../src/index';
chai.use(sinonChai);
chai.use(function(_chai, utils) {
const Assertion = _chai['Assertion'];
Assertion.addProperty('$state');
function getStateFlagName(state) {
if (state === 0) return 'none';
const names = [];
if (state & State.isBinding) names.push('isBinding');
if (state & State.isBound) names.push('isBound');
if (state & State.isAttaching) names.push('isAttaching');
if (state & State.isAttached) names.push('isAttached');
if (state & State.isMounted) names.push('isMounted');
if (state & State.isDetaching) names.push('isDetaching');
if (state & State.isUnbinding) names.push('isUnbinding');
if (state & State.isCached) names.push('isCached');
return names.join('|');
}
for (const stateFlag of [
State.none,
State.isBinding,
State.isBound,
State.isAttaching,
State.isAttached,
State.isMounted,
State.isDetaching,
示例4: require
/* tslint:disable:no-unused-expression */
import logger from "./logger"
import { isPortAvailable } from "./net"
const chai = require("chai")
const chaiAsPromised = require("chai-as-promised")
const expect = chai.expect
chai.use(chaiAsPromised)
describe("Net", () => {
const port = 4567
const host = "0.0.0.0"
const specialPort = process.platform.match("win") ? -1 : 80
describe("#isPortAvailable", () => {
context("when the port is not allowed to be bound", () => {
it("returns a rejected promise", () => {
return expect(isPortAvailable(specialPort, host)).to.eventually.be
.rejected
})
})
context("when the port is available", () => {
it("returns a fulfilled promise", () => {
return expect(isPortAvailable(port, host)).to.eventually.be.fulfilled
})
})
context("when the port is unavailable", () => {
it("returns a rejected promise", () => {
createServer(port).then((_: { close(): any }) => {
示例5:
import * as _ from 'lodash';
import * as chai from 'chai';
import * as sinon from 'sinon';
import * as sinonChai from 'sinon-chai';
chai.use(sinonChai);
let expect: Chai.ExpectStatic = chai.expect;
describe('basics', () => {
describe('primitivos', () => {
it('deve ser assertivo nos tipos', () => {
let booleanVar: boolean = true || false;
let stringVar: string = 'string';
let numberVar: number = 0;
let undefinedVar: any = undefined;
let nullVar: any = null;
expect(booleanVar).to.be.a('boolean');
expect(stringVar).to.be.a('string');
expect(numberVar).to.be.a('number');
expect(undefinedVar).to.be.undefined;
expect(nullVar).to.be.null;
});
});
describe('declaração de variáveis', () => {
it('deve retornar undefined se variável não for atribuída', () => {
let a: string;
expect(a).to.be.undefined;
示例6: test_somethingSyntax
import * as chai from 'chai';
import * as chaiThings from 'chai-things';
chai.use(chaiThings);
function test_somethingSyntax() {
[].should.not.include.something();
[].should.not.include.something.that.equals(1);
var array = [{ a: 1 }, { b: 2 }];
array.should.include.something();
array.should.include.something.that.deep.equals({ b: 2 });
array.should.include.something.that.not.deep.equals({ b: 2 });
array.should.not.include.something.that.deep.equals({ c: 3 });
array.should.include.something.that.not.deep.equals({ c: 3 });
array.should.include.something.with.property('b', 2);
array.should.not.include.something.with.property('b', 3);
chai.expect(array).to.include.something();
chai.expect(array).to.include.something.that.deep.equals({ b: 2 });
chai.expect(array).to.include.something.that.not.deep.equals({ b: 2 });
chai.expect(array).not.to.include.something.that.deep.equals({ c: 3 });
chai.expect(array).to.include.something.that.not.deep.equals({ c: 3 });
chai.expect(array).to.include.something.with.property('b', 2);
chai.expect(array).not.to.include.something.with.property('b', 3);
var array2 = [{ a: 'b' }, { a: 'b' }];
array2.should.include.something.that.have.property("a");
array2.should.include.something.that.have.property("a").not.equal("d");
chai.expect(array2).to.include.something.that.have.property("a");
示例7: constructor
import * as chai from 'chai';
import { expect } from 'chai';
import * as spies from 'chai-spies';
import { getInfos } from './query.service';
chai.use(spies);
describe('Query service', () => {
class MockRes {
code: number;
data: any;
constructor() {}
status(status: number) {
this.code = status;
}
send(data: any) {
this.data = data;
}
}
it('should call find of model', () => {
const spy = chai.spy();
const model = {
find: () => {
spy();
return Promise.resolve([{key: 'foo', value: 'bar'}]);
}
};
示例8: chaiPlugin
/* eslint-env mocha */
// @flow
import { expect, use } from 'chai';
import Kefir from 'kefir';
import { chaiPlugin } from 'brookjs-desalinate';
import view from '../view';
const { plugin, stream, prop, value, send, error, end } = chaiPlugin({ Kefir });
use(plugin);
describe('view', () => {
it('should be a function', () => {
expect(view).to.be.a('function');
});
it('should take a callback and return a function', () => {
expect(view(x => x)).to.be.a('function');
});
it('should be able to be passed to Observable#thru', () => {
expect(stream().thru(view(x => x))).to.be.an.observable.stream();
expect(prop().thru(view(x => x))).to.be.an.observable.property();
});
it('should emit result from function callback', () => {
const a = stream();
expect(a.thru(view(x => !x))).to.emit([value(true)], () => {
send(a, [value(false)]);
});
});