Skip to content

Commit

Permalink
Chai tweaks (#511)
Browse files Browse the repository at this point in the history
* chai.truncateThreshold is a number

* chai.length() is callable
  • Loading branch information
scottnonnenberg authored and ryyppy committed Dec 22, 2016
1 parent c4483dc commit 60acee2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions definitions/npm/chai_v3.5.x/flow_v0.24.0-/chai_v3.5.x.js
Expand Up @@ -44,7 +44,7 @@ declare module "chai" {
& (name: string) => ExpectChain<mixed>
),

length: ExpectChain<number>,
length: (value: number) => ExpectChain<T> | ExpectChain<number>,
lengthOf: (value: number) => ExpectChain<T>,

match: (regex: RegExp) => ExpectChain<T>,
Expand Down Expand Up @@ -182,6 +182,6 @@ declare module "chai" {
declare var config: {
includeStack: boolean,
showDiff: boolean,
truncateThreshold: boolean
truncateThreshold: number
};
}
34 changes: 26 additions & 8 deletions definitions/npm/chai_v3.5.x/test_chai_v3.5.x.js
@@ -1,6 +1,6 @@
/* @flow */

import {expect, assert} from "chai";
import {expect, assert, config} from "chai";

/**
* Word chains
Expand All @@ -10,6 +10,25 @@ expect(true)
.is.of.same.that.to.which
.with.not.deep.any.all.a.an.eql(false);

// $ExpectError
expect(1).to.what("nope");

/**
* Config
*/
config.includeStack = true;
config.showDiff = true;
config.truncateThreshold = 200;

// $ExpectError
config.includeStack = 100;

// $ExpectError
config.showDiff = 100;

// $ExpectError
config.truncateThreshold = true;

/**
* Simple Assertions
*/
Expand Down Expand Up @@ -40,6 +59,9 @@ expect({a: 1}).to.have.property("a", 1);

expect([1,2,3]).to.have.length.above(2);
expect([1,2,3]).to.have.lengthOf(3);
expect([1,2,3]).to.have.length(3);
// $ExpectError
expect([1,2,3]).to.have.length('three');

expect("abc").to.match(/[a-z]{3}/);
expect("abc").to.have.string("b");
Expand Down Expand Up @@ -72,13 +94,9 @@ expect((x) => x).to.change({val: 0}, 'val');
expect((x) => x).to.increase({val: 0}, 'val');
expect((x) => x).to.decrease({val: 0}, 'val');


// $ExpectError
expect(1).to.what("nope");

//
// assert API (http://chaijs.com/api/assert/)
//
/**
* assert API (http://chaijs.com/api/assert/)
*/

// expression
assert("1" === "1", 'with message');
Expand Down

0 comments on commit 60acee2

Please sign in to comment.