Skip to content

Commit

Permalink
switch to expect.not.* format, fix string validation in asymmetric ma…
Browse files Browse the repository at this point in the history
…tcher
  • Loading branch information
quantizor committed Mar 4, 2018
1 parent e81639d commit 0ce480b
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 128 deletions.
61 changes: 30 additions & 31 deletions docs/ExpectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,6 @@ describe('Beware of a misunderstanding! A sequence of dice rolls', () => {
});
```

### `expect.arrayNotContaining(array)`

`expect.arrayNotContaining(array)` matches a received array which contains none of
the elements in the expected array. That is, the expected array **is not a subset**
of the received array.

It is the inverse of `expect.arrayContaining`.

### `expect.assertions(number)`

`expect.assertions(number)` verifies that a certain number of assertions are
Expand Down Expand Up @@ -281,6 +273,36 @@ test('prepareState prepares a valid state', () => {
The `expect.hasAssertions()` call ensures that the `prepareState` callback
actually gets called.

### `expect.not.arrayContaining(array)`

`expect.not.arrayContaining(array)` matches a received array which contains none of
the elements in the expected array. That is, the expected array **is not a subset**
of the received array.

It is the inverse of `expect.arrayContaining`.

### `expect.not.objecttContaining(object)`

`expect.not.objectContaining(object)` matches any received object that does not recursively
match the expected properties. That is, the expected object **is not a subset** of
the received object. Therefore, it matches a received object which contains
properties that are **not** in the expected object.

It is the inverse of `expect.objectContaining`.

### `expect.not.stringContaining(string)`

`expect.not.stringContaining(string)` matches any received string that does not contain the
exact expected string.

It is the inverse of `expect.stringContaining`.

### `expect.not.stringMatching(regexp)`

`expect.not.stringMatching(regexp)` matches any received string that does not match the
expected regexp.

It is the inverse of `expect.stringMatching`.

### `expect.objectContaining(object)`

Expand Down Expand Up @@ -309,27 +331,11 @@ test('onPress gets called with the right thing', () => {
});
```

### `expect.objectNotContaining(object)`

`expect.objectNotContaining(object)` matches any received object that does not recursively
match the expected properties. That is, the expected object **is not a subset** of
the received object. Therefore, it matches a received object which contains
properties that are **not** in the expected object.

It is the inverse of `expect.objectContaining`.

### `expect.stringContaining(string)`

`expect.stringContaining(string)` matches any received string that contains the
exact expected string.

### `expect.stringNotContaining(string)`

`expect.stringNotContaining(string)` matches any received string that does not contain the
exact expected string.

It is the inverse of `expect.stringContaining`.

### `expect.stringMatching(regexp)`

`expect.stringMatching(regexp)` matches any received string that matches the
Expand Down Expand Up @@ -363,13 +369,6 @@ describe('stringMatching in arrayContaining', () => {
});
```

### `expect.stringNotMatching(regexp)`

`expect.stringNotMatching(regexp)` matches any received string that does not match the
expected regexp.

It is the inverse of `expect.stringMatching`.

### `expect.addSnapshotSerializer(serializer)`

You can call `expect.addSnapshotSerializer` to add a module that formats
Expand Down

This file was deleted.

26 changes: 20 additions & 6 deletions packages/expect/src/__tests__/asymmetric_matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,37 +188,41 @@ test('ObjectNotContaining throws for non-objects', () => {
test('StringContaining matches string against string', () => {
jestExpect(stringContaining('en*').asymmetricMatch('queen*')).toBe(true);
jestExpect(stringContaining('en').asymmetricMatch('queue')).toBe(false);
jestExpect(stringContaining('en').asymmetricMatch({})).toBe(false);
});

test('StringContaining throws for non-strings', () => {
jestExpect(() => {
stringContaining([1]).asymmetricMatch('queen');
}).toThrow();

jestExpect(() => {
stringContaining('en*').asymmetricMatch(1);
}).toThrow();
});

test('StringNotContaining matches string against string', () => {
jestExpect(stringNotContaining('en*').asymmetricMatch('queen*')).toBe(false);
jestExpect(stringNotContaining('en').asymmetricMatch('queue')).toBe(true);
jestExpect(stringNotContaining('en').asymmetricMatch({})).toBe(true);
});

test('StringNotContaining throws for non-strings', () => {
jestExpect(() => {
stringNotContaining([1]).asymmetricMatch('queen');
}).toThrow();

jestExpect(() => {
stringNotContaining('en*').asymmetricMatch(1);
}).toThrow();
});

test('StringMatching matches string against regexp', () => {
jestExpect(stringMatching(/en/).asymmetricMatch('queen')).toBe(true);
jestExpect(stringMatching(/en/).asymmetricMatch('queue')).toBe(false);
jestExpect(stringMatching(/en/).asymmetricMatch({})).toBe(false);
});

test('StringMatching matches string against string', () => {
jestExpect(stringMatching('en').asymmetricMatch('queen')).toBe(true);
jestExpect(stringMatching('en').asymmetricMatch('queue')).toBe(false);
jestExpect(stringMatching('en').asymmetricMatch({})).toBe(false);
});

test('StringMatching throws for non-strings and non-regexps', () => {
Expand All @@ -227,20 +231,30 @@ test('StringMatching throws for non-strings and non-regexps', () => {
}).toThrow();
});

test('StringMatching throws for non-string actual values', () => {
jestExpect(() => {
stringMatching('en').asymmetricMatch(1);
}).toThrow();
});

test('StringNotMatching matches string against regexp', () => {
jestExpect(stringNotMatching(/en/).asymmetricMatch('queen')).toBe(false);
jestExpect(stringNotMatching(/en/).asymmetricMatch('queue')).toBe(true);
jestExpect(stringNotMatching(/en/).asymmetricMatch({})).toBe(true);
});

test('StringNotMatching matches string against string', () => {
jestExpect(stringNotMatching('en').asymmetricMatch('queen')).toBe(false);
jestExpect(stringNotMatching('en').asymmetricMatch('queue')).toBe(true);
jestExpect(stringNotMatching('en').asymmetricMatch({})).toBe(true);
});

test('StringNotMatching throws for non-strings and non-regexps', () => {
jestExpect(() => {
stringNotMatching([1]).asymmetricMatch('queen');
}).toThrow();
});

test('StringNotMatching throws for non-string actual values', () => {
jestExpect(() => {
stringNotMatching('en').asymmetricMatch(1);
}).toThrow();
});
Loading

0 comments on commit 0ce480b

Please sign in to comment.