本文整理汇总了TypeScript中tape.test函数的典型用法代码示例。如果您正苦于以下问题:TypeScript test函数的具体用法?TypeScript test怎么用?TypeScript test使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了test函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
import { autobindMethods } from '../../lib/objects';
import { test } from 'tape';
test('autobindMethods()', function(t) {
t.test('it binds methods by name to an instance', function(st) {
st.plan(4);
class Foobar {
foo() {
return this;
}
bar() {
return this;
}
baz() {
return this;
}
}
autobindMethods(Foobar, 'foo', 'bar');
let instance = new Foobar();
let { foo, bar, baz } = instance;
st.equal(foo(), instance);
st.equal(bar(), instance);
st.equal(bar(), instance);
st.equal(baz(), undefined);
});
});
示例2: test
test('curryN()', function(t) {
t.test('it curries a function\'s arguments', function(st) {
let curriedFunc;
st.plan(1);
function func(a, b, c, d) {
st.same([a, b, c, d], [1, 2, 3, 4]);
}
curriedFunc = curryN(func);
curriedFunc(1)(2)(3)(4);
});
t.test('it accepts an optional arity argument', function(st) {
let curriedFunc;
st.plan(1);
function func(a, b, c, d, e) { // eslint-disable-line
st.same([a, b, c], [1, 2, 3]);
}
curriedFunc = curryN(func, 3);
curriedFunc(1)(2)(3);
});
t.test('two calls to same curried func will not affect each other', function(st) {
let result;
let firstCurried;
st.plan(2);
function func(a, b, c, d) {
result = [a, b, c, d];
}
firstCurried = curryN(func)(1)(2);
firstCurried(3)(4);
st.same(result, [1, 2, 3, 4]);
firstCurried(5)(6);
st.same(result, [1, 2, 5, 6]);
});
});
示例3:
Tape.test("taking items", (test: any) => {
test.test("taking no items", (test: any) => {
test.test("no items returned if none input", (test: any) => {
let data: Array<any> = [];
let queryable = new Queryable<any>(data);
queryable.take(0);
test.equal(queryable.toArray().length, 0);
test.end();
});
test.test("no items returned if one input", (test: any) => {
let data: Array<any> = [{}];
let queryable = new Queryable<any>(data);
queryable.take(0);
test.equal(queryable.toArray().length, 0);
test.end();
});
});
test.test("taking one item", (test: any) => {
test.test("one item returned if one input", (test: any) => {
let data: Array<any> = [{}];
let queryable = new Queryable<any>(data);
queryable.take(1);
test.equal(queryable.toArray().length, 1);
test.end();
});
test.test("one item returned if two input", (test: any) => {
let data: Array<any> = [{}, {}];
let queryable = new Queryable<any>(data);
queryable.take(1);
test.equal(queryable.toArray().length, 1);
test.end();
});
});
test.test("taking one item after skiping one item", (test: any) => {
test.test("no items returned if one input", (test: any) => {
let data: Array<any> = [{}];
let queryable = new Queryable<any>(data);
queryable.skip(1);
queryable.take(1);
test.equal(queryable.toArray().length, 0);
test.end();
});
test.test("one item returned if two input", (test: any) => {
let data: Array<any> = [{}, {}];
let queryable = new Queryable<any>(data);
queryable.skip(1);
queryable.take(1);
test.equal(queryable.toArray().length, 1);
test.end();
});
test.test("one item returned if three input", (test: any) => {
let data: Array<any> = [{}, {}, {}];
let queryable = new Queryable<any>(data);
queryable.skip(1);
queryable.take(1);
test.equal(queryable.toArray().length, 1);
test.end();
});
});
});
示例4: test
import { reduce } from '../../lib/functional';
import { test } from 'tape';
import testCurriedMethod from './testCurriedMethod';
test('reduce()', function(t) {
let args = [function() {}, 0];
testCurriedMethod(t, reduce, 'reduce', args);
});
示例5: test
import { flatten } from '../../lib/array_utils';
import { test } from 'tape';
const TEST_ARRAY = [1, 2, [3, 4, [5, 6, [7], 8], 9, 10], 11, [12, [13, 14]]];
test('flatten()', function(t) {
t.test('it flattens a multi-dimensional array', function(st) {
st.plan(1);
st.deepEqual(
flatten(TEST_ARRAY),
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
);
});
t.test('it stops recursing at level when it is specified', function(st) {
st.plan(1);
st.deepEqual(
flatten(TEST_ARRAY, 2),
[1, 2, 3, 4, 5, 6, [7], 8, 9, 10, 11, 12, 13, 14]
);
});
});
示例6: test
import { test } from 'tape';
test('timeout()', function(t) {
let clock,
sandbox;
let wrapper = beforeAndAfterTest(
function() {
sandbox = sinon.sandbox.create();
clock = sandbox.useFakeTimers();
},
function() {
sandbox.restore();
}
);
t.test('it resolves a promise after a given amount of time', wrapper(function(st) {
let resolveSpy = sandbox.spy(),
promise = timeout(1000);
st.plan(2);
promise.then(resolveSpy);
clock.tick(999);
st.ok(!resolveSpy.called, 'Does not resolve before time.');
clock.tick(1);
st.ok(!resolveSpy.calledOnce, 'Does resolve after time.');
}));
});
示例7: test
import { test } from 'tape';
import { Anagram } from './anagram';
test('should get the name right', t => {
const anagram = new Anagram('oh, hi Mark')
const expected = 'oh, hi Mark'
t.equal(anagram.innerText, expected)
t.end()
})
test('should innerTexts equal', t => {
const anagram = new Anagram('oh, hi Mark')
const anagramCopy = new Anagram('oh, hi Mark')
t.equal(anagram.innerText, anagramCopy.innerText)
t.end()
})
示例8: test
/// <reference path="../typings/index.d.ts" />
import {test} from 'tape';
import {Observable} from 'rxjs';
import * as index from '../index';
test('readfile and rxjs', t => {
t.equal(
index.readFileStream('foo') instanceof Observable,
true,
'it should return an Observable'
);
t.end();
});
test('writefile and rxjs', t => {
t.equal(
index.writeFileStream('./foo')('foo') instanceof Observable,
true,
'it should return an Observable'
);
t.end();
});
test('map a xml file into an object', t => {
t.plan(1);
示例9:
/*
* Copyright 2016 Franรงois de Campredon <francois.de.campredon@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as tape from 'tape';
import isNonEmptyString from '../../src/utils/IsNonEmptyString';
tape.test('isPlainObject', t => {
t.equal(isNonEmptyString({}), false, 'it should not accept object');
t.equal(isNonEmptyString(true), false, 'it should not accept booolean');
t.equal(isNonEmptyString(3), false, 'it should not accept number');
t.equal(isNonEmptyString(''), false, 'it should accept plain empty string');
t.equal(isNonEmptyString('foo'), true, 'it should accept non empty string');
t.end();
});
示例10:
Tape.test("Sorting items", (test: any) => {
test.test("sorting items by name", (test: any) => {
test.test("two items ordered ascending returned by name A-Z", (test: any) => {
let data: Array<any> = [{ name: "Anna"}, { name: "zebra"}];
let queryable = new Queryable<any>(data);
queryable.sortBy("name");
test.equal(queryable.toArray()[0].name, "Anna");
test.equal(queryable.toArray()[1].name, "zebra");
test.end();
});
test.test("two items ordered descending returned by name A-Z", (test: any) => {
let data: Array<any> = [{ name: "zebra"}, { name: "Anna"}];
let queryable = new Queryable<any>(data);
queryable.sortBy("name");
test.equal(queryable.toArray()[0].name, "Anna");
test.equal(queryable.toArray()[1].name, "zebra");
test.end();
});
});
test.test("sorting items by name descending", (test: any) => {
test.test("two items ordered ascending returned by name Z-A", (test: any) => {
let data: Array<any> = [{ name: "Anna"}, { name: "zebra"}];
let queryable = new Queryable<any>(data);
queryable.sortByDescending("name");
test.equal(queryable.toArray()[0].name, "zebra");
test.equal(queryable.toArray()[1].name, "Anna");
test.end();
});
test.test("two items ordered descending returned by name Z-A", (test: any) => {
let data: Array<any> = [{ name: "zebra"}, { name: "Anna"}];
let queryable = new Queryable<any>(data);
queryable.sortByDescending("name");
test.equal(queryable.toArray()[0].name, "zebra");
test.equal(queryable.toArray()[1].name, "Anna");
test.end();
});
});
});