Skip to content

Commit

Permalink
Test empty Immutable collections with {min: false} option (jestjs#4121)
Browse files Browse the repository at this point in the history
* Test empty Immutable collections with {min: false} option

* Make neutral change to code to see if it helps CI

* Fix 2 prettier lint errors
  • Loading branch information
pedrottimark authored and cpojer committed Jul 26, 2017
1 parent 1c934dc commit ecbebd0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
66 changes: 59 additions & 7 deletions packages/pretty-format/src/__tests__/immutable.test.js
Expand Up @@ -22,12 +22,18 @@ const toPrettyPrintTo = expectUtil.getPrettyPrint(
expect.extend({toPrettyPrintTo});

describe('Immutable.OrderedSet plugin', () => {
it('supports an empty set', () => {
it('supports an empty collection {min: true}', () => {
expect(
Immutable.OrderedSet([]),
).toPrettyPrintTo('Immutable.OrderedSet []', {min: true});
});

it('supports an empty collection {min: false}', () => {
expect(
Immutable.OrderedSet([]),
).toPrettyPrintTo('Immutable.OrderedSet [\n]', {min: false});
});

it('supports a single string element', () => {
expect(
Immutable.OrderedSet(['foo']),
Expand Down Expand Up @@ -109,12 +115,18 @@ describe('Immutable.OrderedSet plugin', () => {
});

describe('Immutable.List plugin', () => {
it('supports an empty set', () => {
it('supports an empty collection {min: true}', () => {
expect(Immutable.List([])).toPrettyPrintTo('Immutable.List []', {
min: true,
});
});

it('supports an empty collection {min: false}', () => {
expect(Immutable.List([])).toPrettyPrintTo('Immutable.List [\n]', {
min: false,
});
});

it('supports a single string element', () => {
expect(Immutable.List(['foo'])).toPrettyPrintTo('Immutable.List ["foo"]', {
min: true,
Expand Down Expand Up @@ -184,12 +196,18 @@ describe('Immutable.List plugin', () => {
});

describe('Immutable.Stack plugin', () => {
it('supports an empty set', () => {
it('supports an empty collection {min: true}', () => {
expect(Immutable.Stack([])).toPrettyPrintTo('Immutable.Stack []', {
min: true,
});
});

it('supports an empty collection {min: false}', () => {
expect(Immutable.Stack([])).toPrettyPrintTo('Immutable.Stack [\n]', {
min: false,
});
});

it('supports a single string element', () => {
expect(
Immutable.Stack(['foo']),
Expand Down Expand Up @@ -261,10 +279,16 @@ describe('Immutable.Stack plugin', () => {
});

describe('Immutable.Set plugin', () => {
it('supports an empty set', () => {
it('supports an empty collection {min: true}', () => {
expect(Immutable.Set([])).toPrettyPrintTo('Immutable.Set []', {min: true});
});

it('supports an empty collection {min: false}', () => {
expect(Immutable.Set([])).toPrettyPrintTo('Immutable.Set [\n]', {
min: false,
});
});

it('supports a single string element', () => {
expect(Immutable.Set(['foo'])).toPrettyPrintTo('Immutable.Set ["foo"]', {
min: true,
Expand Down Expand Up @@ -333,10 +357,16 @@ describe('Immutable.Set plugin', () => {
});

describe('Immutable.Map plugin', () => {
it('supports an empty set', () => {
it('supports an empty collection {min: true}', () => {
expect(Immutable.Map({})).toPrettyPrintTo('Immutable.Map {}', {min: true});
});

it('supports an empty collection {min: false}', () => {
expect(Immutable.Map({})).toPrettyPrintTo('Immutable.Map {\n}', {
min: false,
});
});

it('supports an object with single key', () => {
expect(Immutable.Map({a: 1})).toPrettyPrintTo('Immutable.Map {a: 1}', {
min: true,
Expand Down Expand Up @@ -390,12 +420,18 @@ describe('Immutable.Map plugin', () => {
});

describe('Immutable.OrderedMap plugin', () => {
it('supports an empty set', () => {
it('supports an empty collection {min: true}', () => {
expect(
Immutable.OrderedMap({}),
).toPrettyPrintTo('Immutable.OrderedMap {}', {min: true});
});

it('supports an empty collection {min: false}', () => {
expect(
Immutable.OrderedMap({}),
).toPrettyPrintTo('Immutable.OrderedMap {\n}', {min: false});
});

it('supports an object with single key', () => {
expect(
Immutable.OrderedMap({a: 1}),
Expand Down Expand Up @@ -449,7 +485,23 @@ describe('Immutable.OrderedMap plugin', () => {
});

describe('Immutable.Record plugin', () => {
it('supports an empty record', () => {
it('supports an empty record {min: true}', () => {
const ABRecord = Immutable.Record({}, 'ABRecord');

expect(new ABRecord()).toPrettyPrintTo('Immutable.ABRecord {}', {
min: true,
});
});

it('supports an empty record {min: false}', () => {
const ABRecord = Immutable.Record({}, 'ABRecord');

expect(new ABRecord()).toPrettyPrintTo('Immutable.ABRecord {\n}', {
min: false,
});
});

it('supports a record with descriptive name', () => {
const ABRecord = Immutable.Record({a: 1, b: 2}, 'ABRecord');

expect(new ABRecord()).toPrettyPrintTo('Immutable.ABRecord {a: 1, b: 2}', {
Expand Down
4 changes: 2 additions & 2 deletions packages/pretty-format/src/plugins/lib/print_immutable.js
Expand Up @@ -16,7 +16,7 @@ const SPACE = ' ';
const addKey = (isMap: boolean, key: any) => (isMap ? key + ': ' : '');

const addFinalEdgeSpacing = (length: number, edgeSpacing: string) =>
length > 0 ? edgeSpacing : '';
length !== 0 ? edgeSpacing : '';

const printImmutable = (
val: any,
Expand Down Expand Up @@ -51,7 +51,7 @@ const printImmutable = (
}

result += immutableArray.join(',' + opts.spacing);
if (!opts.min && immutableArray.length > 0) {
if (!opts.min && immutableArray.length !== 0) {
result += ',';
}

Expand Down

0 comments on commit ecbebd0

Please sign in to comment.