Skip to content

Commit

Permalink
[Tests] add Debug typeName tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 22, 2018
1 parent 2113c8d commit fc9fadf
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/enzyme-test-suite/test/Debug-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
indent,
debugNode,
debugNodes,
typeName,
} from 'enzyme/build/Debug';

import './_helpers/setupAdapters';
Expand All @@ -22,6 +23,31 @@ const { adapter } = get();
const debugElement = element => debugNode(adapter.elementToNode(element));

describe('debug', () => {
describe('typeName(node)', () => {
it('returns `.type` when not a function', () => {
const type = {};
expect(typeName({ type })).to.equal(type);
});

describe('when `.type` is a function', () => {
it('returns the function’s name', () => {
function Foo() {}
expect(typeName({ type: Foo })).to.equal('Foo');
});

it('returns the function’s `.displayName` when present', () => {
function Foo() {}
Foo.displayName = 'Bar';
expect(typeName({ type: Foo })).to.equal('Bar');
});

it('returns "Component" when the function is anonymous', () => {
const anon = Object(() => {});
expect(typeName({ type: anon })).to.equal('Component');
});
});
});

describe('spaces(n)', () => {
it('should return n spaces', () => {
expect(spaces(4)).to.equal(' ');
Expand Down

0 comments on commit fc9fadf

Please sign in to comment.