Skip to content

Commit

Permalink
Tests: Add getBlockAttribute unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Oct 16, 2017
1 parent 5aec740 commit 57f0684
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion blocks/api/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function matcherFromSource( sourceConfig ) {
}

/**
* Given an attribute key, an attributes schema, a block's raw content and the commentAttributes
* Given an attribute key, an attribute's schema, a block's raw content and the commentAttributes
* returns the attribute value depending on its source definition of the given attribute key
*
* @param {string} attributeKey Attribute key
Expand Down
45 changes: 45 additions & 0 deletions blocks/api/test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { noop } from 'lodash';
* Internal dependencies
*/
import {
getBlockAttribute,
getBlockAttributes,
asType,
createBlockWithFallback,
Expand Down Expand Up @@ -76,6 +77,50 @@ describe( 'block parser', () => {
} );
} );

describe( 'getBlockAttribute', () => {
it( 'should return the comment attribute value', () => {
const value = getBlockAttribute(
'number',
{
type: 'number',
source: 'comment',
},
'',
{ number: 10 }
);

expect( value ).toBe( 10 );
} );

it( 'should return the matcher\'s attribute value', () => {
const value = getBlockAttribute(
'content',
{
type: 'string',
source: 'text',
selector: 'div',
},
'<div>chicken</div>',
{}
);
expect( value ).toBe( 'chicken' );
} );

it( 'should return undefined for meta attributes', () => {
const value = getBlockAttribute(
'content',
{
type: 'string',
source: 'meta',
meta: 'content',
},
'<div>chicken</div>',
{}
);
expect( value ).toBeUndefined();
} );
} );

describe( 'getBlockAttributes()', () => {
it( 'should merge attributes with the parsed and default attributes', () => {
const blockType = {
Expand Down

0 comments on commit 57f0684

Please sign in to comment.