Skip to content

Commit

Permalink
Remove default prefix and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcohamersma committed Jun 5, 2015
1 parent b71bce5 commit d3a5ad3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 40 deletions.
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ module.exports = function(options) {
options = { name: options };
}

if (options.prefix === void 0) {
options.prefix = 'c-';
}

return function(element, modifiers, extraClassNames) {
var blockName = options.name,
rootName = blockName,
Expand Down
70 changes: 34 additions & 36 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,74 +10,60 @@ function resultWithClassName(className) {
describe('react-bem-helper', function() {
var bemhelper = new BEMhelper('block');

describe('with custom prefix', function() {
it('should remove prefix when empty', function() {
var bemhelperWithoutPrefix = new BEMhelper({
name: 'block',
prefix: ''
});

var bemhelperWithoutPrefix2 = new BEMhelper({
name: 'block',
prefix: null
});

expect(bemhelperWithoutPrefix('')).toEqual(resultWithClassName('block'));
expect(bemhelperWithoutPrefix2('')).toEqual(resultWithClassName('block'));
it('should return className for the block when no arguments given', function() {
var bemhelperWithoutPrefix = new BEMhelper({
name: 'block',
prefix: ''
});

it('should have custom prefix when one is set', function() {
var bemhelperCustomPrefix = new BEMhelper({
name: 'block',
prefix: 'mh-'
});

expect(bemhelperCustomPrefix('')).toEqual(resultWithClassName('mh-block'));
var bemhelperWithoutPrefix2 = new BEMhelper({
name: 'block',
prefix: null
});
});

it('should return className for the block when no arguments given', function() {
expect(bemhelper('')).toEqual(resultWithClassName('c-block'));

expect(bemhelper()).toEqual(resultWithClassName('c-block'));
expect(bemhelper('')).toEqual(resultWithClassName('block'));
expect(bemhelper()).toEqual(resultWithClassName('block'));
expect(bemhelperWithoutPrefix('')).toEqual(resultWithClassName('block'));
expect(bemhelperWithoutPrefix2('')).toEqual(resultWithClassName('block'));
});

it('should return classNames for the block and modifier when modifier given', function() {
expect(bemhelper('', 'funny')).toEqual(resultWithClassName('c-block c-block--funny'));
expect(bemhelper('', 'funny')).toEqual(resultWithClassName('block block--funny'));
});

it('should return className for the element when element is given', function() {
expect(bemhelper('element')).toEqual(resultWithClassName('c-block__element'));
expect(bemhelper('element')).toEqual(resultWithClassName('block__element'));
});

it('should return classNames for the element and the modifier when a modifier is given', function() {
expect(bemhelper('element', 'modifier')).toEqual(resultWithClassName('c-block__element c-block__element--modifier'));
expect(bemhelper('element', 'modifier')).toEqual(resultWithClassName('block__element block__element--modifier'));
});

describe(', when given multiple modifiers', function() {
it('as an array, should return classNames for the element and each modifier given', function() {
var modifiers = ['one', 'two'];
expect(bemhelper('', modifiers)).toEqual(resultWithClassName('c-block c-block--one c-block--two'));
expect(bemhelper('', modifiers)).toEqual(resultWithClassName('block block--one block--two'));
});

it('as an object, should return classNames for the element and each modifier that is truthy', function() {
var modifiers = {
'one': false,
'two': true,
'three': false,
'four': function() { return false; }
'four': function() { return false; },
'five': function() { return true; }
};

expect(bemhelper('', modifiers)).toEqual(resultWithClassName('c-block c-block--two'));
expect(bemhelper(null, modifiers)).toEqual(resultWithClassName('c-block c-block--two'));
expect(bemhelper('', modifiers)).toEqual(resultWithClassName('block block--two block--five'));
expect(bemhelper(null, modifiers)).toEqual(resultWithClassName('block block--two block--five'));
});
});

it('should append extra classNames when given as an array', function() {
var extraClasses = ['one', 'two'];
expect(bemhelper('', null, extraClasses)).toEqual(resultWithClassName('c-block one two'));
expect(bemhelper('', null, extraClasses)).toEqual(resultWithClassName('block one two'));

expect(bemhelper('element', '', extraClasses)).toEqual(resultWithClassName('c-block__element one two'));
expect(bemhelper('element', '', extraClasses)).toEqual(resultWithClassName('block__element one two'));
});

it('should append extra classNames for truthy values when given as an object', function() {
Expand All @@ -87,7 +73,19 @@ describe('react-bem-helper', function() {
'three': false
};

expect(bemhelper('', '', extraClasses)).toEqual(resultWithClassName('c-block two'));
expect(bemhelper('', '', extraClasses)).toEqual(resultWithClassName('block two'));
});

it('when given a prefix, should append generated BEM classes with that', function() {
var prefixedBEM = new BEMhelper({
name: 'block',
prefix: 'mh-'
});

expect(prefixedBEM('')).toEqual(resultWithClassName('mh-block'));
expect(prefixedBEM('element')).toEqual(resultWithClassName('mh-block__element'));
expect(prefixedBEM('', 'modifier')).toEqual(resultWithClassName('mh-block mh-block--modifier'));
expect(prefixedBEM('', '', 'class')).toEqual(resultWithClassName('mh-block class'));
});
});

Expand Down

0 comments on commit d3a5ad3

Please sign in to comment.