Skip to content

Commit

Permalink
add fixes for object and array as well
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed May 26, 2018
1 parent bc28e85 commit 75a80f3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
18 changes: 18 additions & 0 deletions packages/pretty-format/src/__tests__/asymmetric_matcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,31 @@ test(`arrayContaining()`, () => {
]`);
});

test(`arrayNotContaining()`, () => {
const result = prettyFormat(expect.not.arrayContaining([1, 2]), options);
expect(result).toEqual(`ArrayNotContaining [
1,
2,
]`);
});

test(`objectContaining()`, () => {
const result = prettyFormat(expect.objectContaining({a: 'test'}), options);
expect(result).toEqual(`ObjectContaining {
"a": "test",
}`);
});

test(`objectNotContaining()`, () => {
const result = prettyFormat(
expect.not.objectContaining({a: 'test'}),
options,
);
expect(result).toEqual(`ObjectNotContaining {
"a": "test",
}`);
});

test(`stringContaining(string)`, () => {
const result = prettyFormat(expect.stringContaining('jest'), options);
expect(result).toEqual(`StringContaining "jest"`);
Expand Down
10 changes: 8 additions & 2 deletions packages/pretty-format/src/plugins/asymmetric_matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export const serialize = (
): string => {
const stringedValue = val.toString();

if (stringedValue === 'ArrayContaining') {
if (
stringedValue === 'ArrayContaining' ||
stringedValue === 'ArrayNotContaining'
) {
if (++depth > config.maxDepth) {
return '[' + stringedValue + ']';
}
Expand All @@ -37,7 +40,10 @@ export const serialize = (
);
}

if (stringedValue === 'ObjectContaining') {
if (
stringedValue === 'ObjectContaining' ||
stringedValue === 'ObjectNotContaining'
) {
if (++depth > config.maxDepth) {
return '[' + stringedValue + ']';
}
Expand Down

0 comments on commit 75a80f3

Please sign in to comment.