hamjest 3.6.2 → 3.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/@types/index.d.ts CHANGED
@@ -2,7 +2,7 @@ declare module 'hamjest' {
2
2
  type Value = any;
3
3
 
4
4
  export class Matcher {
5
- constructor(fns?: {matches?: (Value) => boolean; describeTo?: (Description) => void; describeMismatch?: (Value, Description) => void});
5
+ constructor(fns?: {matches?: (value: Value) => boolean; describeTo?: (description: Description) => void; describeMismatch?: (value: Value, description: Description) => void});
6
6
  matches(actual: Value): boolean;
7
7
  describeTo(description: Description): void;
8
8
  describeMismatch(value: Value, description: Description): void;
@@ -11,7 +11,7 @@ declare module 'hamjest' {
11
11
  type ValueOrMatcher = Value | Matcher;
12
12
 
13
13
  export class TypeSafeMatcher<T> extends Matcher {
14
- constructor(fns?: {isExpectedType?: (Value) => boolean; matchesSafely?: (T) => boolean; describeTo?: (Description) => void; describeMismatchSafely?: (T, Description) => void});
14
+ constructor(fns?: {isExpectedType?: (value: Value) => boolean; matchesSafely?: (actual: T) => boolean; describeTo?: (description: Description) => void; describeMismatchSafely?: (value: T, description: Description) => void});
15
15
  isExpectedType(actual: Value): boolean;
16
16
  matchesSafely(actual: T): boolean;
17
17
  describeMismatchSafely(value: T, description: Description): void;
@@ -33,8 +33,8 @@ declare module 'hamjest' {
33
33
  get(): string;
34
34
  }
35
35
 
36
- export function assertThat(actual: Value, matcher: Matcher): void;
37
- export function assertThat(reason: string, actual: Value, matcher: Matcher): void;
36
+ export function assertThat(actual: Value, matcher: ValueOrMatcher): void;
37
+ export function assertThat(reason: string, actual: Value, matcher: ValueOrMatcher): void;
38
38
 
39
39
  export function promiseThat(actual: Promise<Value>, matcher: Matcher): Promise<any>;
40
40
  export function promiseThat(reason: string, actual: Promise<Value>, matcher: Matcher): Promise<any>;
@@ -187,7 +187,7 @@ declare module 'hamjest' {
187
187
  export function orderedBy(comparisonFunction: (a: Value, b: Value) => boolean, orderName?: string): TypeSafeMatcher<Array<any>>;
188
188
 
189
189
  // hasSize: require('./matchers/hasSize'),;
190
- export function hasSize(size: number): Matcher;
190
+ export function hasSize(size: ValueOrMatcher): Matcher;
191
191
 
192
192
  // isEmpty: require('./matchers/isEmpty'),;
193
193
  export function isEmpty(): Matcher;
@@ -8,6 +8,8 @@ __.assertThat(2, __.not(__.equalTo(1)));
8
8
  __.assertThat(2, __.is(__.not(1)));
9
9
  __.assertThat(2, __.is(__.not(__.equalTo(1))));
10
10
  __.assertThat(2, __.is(__.not(__.equalTo(1))));
11
+ __.assertThat({one: 1}, {one: 1});
12
+ __.assertThat('a reason', {one: 1}, {one: 1});
11
13
 
12
14
  // Primitives
13
15
  __.assertThat(true, __.truthy());
@@ -52,6 +54,7 @@ __.assertThat(new Date('2015-06-01T14:00:00'), __.beforeOrEqualTo(new Date('2015
52
54
 
53
55
  // Array matcher
54
56
  __.assertThat([1, 2, 3], __.hasSize(3));
57
+ __.assertThat([1, 2, 3], __.hasSize(__.greaterThan(2)));
55
58
  __.assertThat([], __.isEmpty());
56
59
  __.assertThat([], __.empty());
57
60
  __.assertThat([1], __.hasExactlyOneItem(1));
package/README.md CHANGED
@@ -30,17 +30,26 @@ npm install hamjest --save-dev
30
30
  All asserts and matchers are available as children of the `hamjest` module, so just require it, give it an unobtrusive name and start matching:
31
31
 
32
32
  ```JavaScript
33
- var __ = require('hamjest');
33
+ const __ = require('hamjest');
34
34
 
35
35
  __.assertThat('jim the rat', __.containsString('rat'));
36
36
  __.assertThat(5, __.is(__.greaterThan(2)));
37
37
  __.assertThat([5, 12, 9], __.hasItem(__.greaterThanOrEqualTo(11)));
38
38
  ```
39
39
 
40
+ If you’re a TypeScript fan, you can use that as well:
41
+ ```TypeScript
42
+ // You can use destructuring imports if you like…
43
+ import {assertThat, is, greaterThan} from 'hamjest';
44
+
45
+ assertThat(42, is(greaterThan(21)));
46
+ ```
47
+
48
+
40
49
  The best thing about Hamjest are its error messages, just like the [Java original](http://hamcrest.org):
41
50
 
42
51
  ```JavaScript
43
- var sut = {name: 1337, age: 25};
52
+ const sut = {name: 1337, age: 25};
44
53
  __.assertThat(sut, __.hasProperties({name: __.string(), age: __.greaterThan(18)}));
45
54
 
46
55
  AssertionError:
@@ -60,7 +69,7 @@ Expected: a number less than <18>
60
69
 
61
70
  See the [matcher documentation](https://github.com/rluba/hamjest/wiki/Matcher-documentation) for a list of available matchers.
62
71
 
63
- Have a look at the [test suite](./test/) to see lots of usage examples [for each matcher](./test/matchers/) as well as the [assertThat](./test/assertThatSpec.js) and [promiseThat](./test/promiseThatSpec.js) functions.
72
+ Have a look at the [test suite](./test/node/) to see lots of usage examples [for each matcher](./test/node/matchers/) as well as the [assertThat](./test/node/assertThatSpec.js) and [promiseThat](./test/node/promiseThatSpec.js) functions.
64
73
 
65
74
  See the [documentation about promises](https://github.com/rluba/hamjest/wiki/Hamjest-and-Promises) for details about using Hamjest with promises or asserting asynchronously.
66
75
 
@@ -85,7 +94,7 @@ function animalWithName(valueOrMatcher) {
85
94
  return new __.FeatureMatcher(valueOrMatcher, 'animal with name', 'name');
86
95
  }
87
96
 
88
- var animal = {name: 'Bob', age: 12};
97
+ const animal = {name: 'Bob', age: 12};
89
98
  __.assertThat(animal, __.is(animalWithName('Tom')));
90
99
 
91
100
  AssertionError:
@@ -102,7 +111,7 @@ function animalWithNameLength(valueOrMatcher) {
102
111
  });
103
112
  }
104
113
 
105
- var animal = {name: 'bob', age: 12};
114
+ const animal = {name: 'bob', age: 12};
106
115
  __.assertThat(animal, __.is(animalWithNameLength(__.greaterThan(5))));
107
116
 
108
117
  AssertionError:
@@ -123,7 +132,7 @@ Simply include `dist/hamjest(.min).js` in your browser tests. It comes with "bat
123
132
  The browser build exports a single global: `hamjest`. You can rename it as usual for better readability:
124
133
 
125
134
  ```JavaScript
126
- var __ = hamjest;
135
+ const __ = hamjest;
127
136
 
128
137
  __.assertThat('2007-05-01', __.startsWith('2007'));
129
138
  ```