Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test empty Immutable collections with {min: false} option #4121

Merged
merged 3 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 59 additions & 7 deletions packages/pretty-format/src/__tests__/immutable.test.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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