Add definitions for chai-string

This commit is contained in:
Nick Malaguti
2015-12-08 13:08:32 -05:00
parent 17dd34132c
commit cf491bf776
2 changed files with 173 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
/// <reference path="chai-string.d.ts" />
/// <reference path="../mocha/mocha.d.ts" />
/// <reference path="../node/node.d.ts" />
var should = chai.should();
var assert = chai.assert;
var expect = chai.expect;
var chai_string = require('chai-string');
chai.use(chai_string);
describe('chai-string', function() {
describe('#startsWith', function() {
it('check that', function() {
var obj = { foo: 'hello world' };
expect(obj).to.have.property('foo').that.startsWith('hello');
});
});
describe('#startWith', function() {
it('should return true', function() {
var str = 'abcdef',
prefix = 'abc';
str.should.startWith(prefix);
});
it('should return false', function() {
var str = 'abcdef',
prefix = 'cba';
str.should.not.startWith(prefix);
});
});
describe('#endWith', function() {
it('should return true', function() {
var str = 'abcdef',
suffix = 'def';
str.should.endWith(suffix);
});
it('should return false', function() {
var str = 'abcdef',
suffix = 'fed';
str.should.not.endWith(suffix);
});
});
describe('tdd alias', function() {
beforeEach(function() {
this.str = 'abcdef';
this.str2 = 'a\nb\tc\r d ef';
});
it('.startsWith', function() {
assert.startsWith(this.str, 'abc');
});
it('.notStartsWith', function() {
assert.notStartsWith(this.str, 'cba');
});
it('.endsWith', function() {
assert.endsWith(this.str, 'def');
});
it('.notEndsWith', function() {
assert.notEndsWith(this.str, 'fed');
});
it('.equalIgnoreCase', function() {
assert.equalIgnoreCase(this.str, 'AbCdEf');
});
it('.notEqualIgnoreCase', function() {
assert.notEqualIgnoreCase(this.str, 'abDDD');
});
it('.equalIgnoreSpaces', function() {
assert.equalIgnoreSpaces(this.str, this.str2);
});
it('.notEqualIgnoreSpaces', function() {
assert.notEqualIgnoreSpaces(this.str, this.str2 + 'g');
});
it('.singleLine', function() {
assert.singleLine(this.str);
});
it('.notSingleLine', function() {
assert.notSingleLine("abc\ndef");
});
it('.reverseOf', function() {
assert.reverseOf(this.str, 'fedcba');
});
it('.notReverseOf', function() {
assert.notReverseOf(this.str, 'aaaaa');
});
it('.palindrome', function() {
assert.palindrome('abcba');
assert.palindrome('abccba');
assert.palindrome('');
});
it('.notPalindrome', function() {
assert.notPalindrome(this.str);
});
it('.entriesCount', function() {
assert.entriesCount('abcabd', 'ab', 2);
assert.entriesCount('ababd', 'ab', 2);
assert.entriesCount('abab', 'ab', 2);
assert.entriesCount('', 'ab', 0);
});
});
});

45
chai-string/chai-string.d.ts vendored Normal file
View File

@@ -0,0 +1,45 @@
// Type definitions for chai-string 1.1.4
// Project: https://github.com/onechiporenko/chai-string
// Definitions by: Nick Malaguti <https://github.com/nmalaguti/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///<reference path="../chai/chai.d.ts" />
declare module Chai {
interface Assertion extends LanguageChains, NumericComparison, TypeComparison {
startsWith(expected: string, message?: string): Assertion;
startWith(expected: string, message?: string): Assertion;
endsWith(expected: string, message?: string): Assertion;
endWith(expected: string, message?: string): Assertion;
equalIgnoreCase(expected: string, message?: string): Assertion;
equalIgnoreSpaces(expected: string, message?: string): Assertion;
singleLine(message?: string): Assertion;
reverseOf(message?: string): Assertion;
palindrome(message?: string): Assertion;
entriesCount(substr: string, expected: number, message?: string): Assertion;
}
export interface Assert {
startsWith(val: string, exp: string, msg?: string): void;
notStartsWith(val: string, exp: string, msg?: string): void;
endsWith(val: string, exp: string, msg?: string): void;
notEndsWith(val: string, exp: string, msg?: string): void;
equalIgnoreCase(val: string, exp: string, msg?: string): void;
notEqualIgnoreCase(val: string, exp: string, msg?: string): void;
equalIgnoreSpaces(val: string, exp: string, msg?: string): void;
notEqualIgnoreSpaces(val: string, exp: string, msg?: string): void;
singleLine(val: string, msg?: string): void;
notSingleLine(val: string, msg?: string): void;
reverseOf(val: string, exp: string, msg?: string): void;
notReverseOf(val: string, exp: string, msg?: string): void;
palindrome(val: string, msg?: string): void;
notPalindrome(val: string, msg?: string): void;
entriesCount(str: string, substr: string, count: number, msg?: string): void;
}
}
declare module 'chai-string' {
function chaiString(chai: any, utils: any): void;
namespace chaiString {}
export = chaiString;
}