Skip to content

Commit

Permalink
[Tests] use object-inspect for comparisons; add missing info to ada…
Browse files Browse the repository at this point in the history
…pter tests
  • Loading branch information
ljharb committed Aug 18, 2018
1 parent 5774d0d commit fe6f676
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/enzyme-test-suite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"jsdom": "^6.5.1",
"mocha-wrap": "^2.1.2",
"object.assign": "^4.1.0",
"object-inspect": "^1.6.0",
"prop-types": "^15.6.2",
"semver": "^5.5.0",
"sinon": "^4.1.6"
Expand Down
38 changes: 36 additions & 2 deletions packages/enzyme-test-suite/test/Adapter-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect } from 'chai';
import jsdom from 'jsdom';
import { get } from 'enzyme/build/configuration';
import { configure, shallow } from 'enzyme';
import inspect from 'object-inspect';

import './_helpers/setupAdapters';
import Adapter from './_helpers/adapter';
Expand All @@ -21,7 +22,7 @@ import { itIf, describeWithDOM, describeIf } from './_helpers';

const { adapter } = get();

const prettyFormat = o => JSON.stringify(o, null, 2);
const prettyFormat = x => inspect(x).replace(/,/g, ',\n');

// Kind of hacky, but we nullify all the instances to test the tree structure
// with jasmine's deep equality function, and test the instances separate. We
Expand Down Expand Up @@ -154,12 +155,14 @@ describe('Adapter', () => {
nodeType: 'class',
type: Foo,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'host',
type: 'div',
props: {},
key: undefined,
ref: null,
instance: null,
rendered: [
Expand Down Expand Up @@ -191,6 +194,7 @@ describe('Adapter', () => {
nodeType: 'class',
type: Foo,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: null,
Expand Down Expand Up @@ -218,12 +222,14 @@ describe('Adapter', () => {
nodeType: 'function',
type: Foo,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'host',
type: 'div',
props: { className: 'Foo' },
key: undefined,
ref: null,
instance: null,
rendered: ['Hello World!'],
Expand All @@ -247,12 +253,14 @@ describe('Adapter', () => {
nodeType: 'function',
type: Qoo,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'host',
type: 'span',
props: { className: 'Qoo' },
key: undefined,
ref: null,
instance: null,
rendered: ['Hello World!'],
Expand Down Expand Up @@ -282,12 +290,14 @@ describe('Adapter', () => {
nodeType: 'class',
type: Qoo,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'host',
type: 'span',
props: { className: 'Qoo' },
key: undefined,
ref: null,
instance: null,
rendered: ['Hello World!'],
Expand Down Expand Up @@ -317,6 +327,7 @@ describe('Adapter', () => {
nodeType: 'class',
type: Foo,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: null,
Expand Down Expand Up @@ -376,31 +387,36 @@ describe('Adapter', () => {
nodeType: 'class',
type: Bam,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'class',
type: Bar,
props: { special: true },
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'function',
type: Foo,
props: { className: 'special' },
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'host',
type: 'div',
props: { className: 'Foo special' },
key: undefined,
ref: null,
instance: null,
rendered: [
{
nodeType: 'host',
type: 'span',
props: { className: 'Foo2' },
key: undefined,
ref: null,
instance: null,
rendered: ['Literal'],
Expand All @@ -409,12 +425,14 @@ describe('Adapter', () => {
nodeType: 'function',
type: Qoo,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'host',
type: 'span',
props: { className: 'Qoo' },
key: undefined,
ref: null,
instance: null,
rendered: ['Hello World!'],
Expand Down Expand Up @@ -489,31 +507,36 @@ describe('Adapter', () => {
nodeType: 'class',
type: Bam,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'class',
type: Bar,
props: { special: true },
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'class',
type: Foo,
props: { className: 'special' },
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'host',
type: 'div',
props: { className: 'Foo special' },
key: undefined,
ref: null,
instance: null,
rendered: [
{
nodeType: 'host',
type: 'span',
props: { className: 'Foo2' },
key: undefined,
ref: null,
instance: null,
rendered: ['Literal'],
Expand All @@ -522,12 +545,14 @@ describe('Adapter', () => {
nodeType: 'class',
type: Qoo,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'host',
type: 'span',
props: { className: 'Qoo' },
key: undefined,
ref: null,
instance: null,
rendered: ['Hello World!'],
Expand Down Expand Up @@ -624,19 +649,22 @@ describe('Adapter', () => {
nodeType: 'class',
type: Bam,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'class',
type: Bar,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: [
{
nodeType: 'class',
type: Foo,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: null,
Expand All @@ -645,6 +673,7 @@ describe('Adapter', () => {
nodeType: 'class',
type: Foo,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: null,
Expand All @@ -653,6 +682,7 @@ describe('Adapter', () => {
nodeType: 'class',
type: Foo,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: null,
Expand Down Expand Up @@ -703,13 +733,15 @@ describe('Adapter', () => {
nodeType: 'class',
type: Outer,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: {
nodeType: 'class',
type: Inner,
props: {},
// pretty print removes ref because it is a function
key: undefined,
ref: tree.rendered.ref, // prettyFormat loses the reference to "ref"
instance: null,
rendered: null,
},
Expand Down Expand Up @@ -748,6 +780,7 @@ describe('Adapter', () => {
nodeType: 'class',
type: Outer,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: {
Expand Down Expand Up @@ -794,6 +827,7 @@ describe('Adapter', () => {
nodeType: 'class',
type: Outer,
props: {},
key: undefined,
ref: null,
instance: null,
rendered: {
Expand Down

0 comments on commit fe6f676

Please sign in to comment.