-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from bem-sdk/refactor-type
refactor(type): not use `naming.typeOf()`
- Loading branch information
Showing
4 changed files
with
87 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.nyc_output | ||
node_modules | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
.nyc_output | ||
node_modules | ||
coverage | ||
.nyc_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,43 @@ | ||
const test = require('ava'); | ||
const sinon = require('sinon'); | ||
const proxyquire = require('proxyquire'); | ||
|
||
test.beforeEach('setup', t => { | ||
t.context.stub = sinon.stub().returns('type'); | ||
t.context.BemEntityName = proxyquire('../index', { | ||
'bem-naming': { | ||
typeOf: t.context.stub | ||
} | ||
}); | ||
}); | ||
|
||
test('should use `naming.typeOf()` for block', t => { | ||
const entity = new t.context.BemEntityName({ block: 'block' }); | ||
const BemEntityName = require('../index'); | ||
|
||
/*eslint no-unused-expressions: "off"*/ | ||
entity.type; | ||
test('should determine block', t => { | ||
const entityName = new BemEntityName({ block: 'block' }); | ||
|
||
t.truthy(t.context.stub.calledWith({ block: 'block' })); | ||
t.is(entityName.type, 'block'); | ||
}); | ||
|
||
test('should use `naming.typeOf()` for elem', t => { | ||
const entity = new t.context.BemEntityName({ block: 'block', elem: 'elem' }); | ||
|
||
/*eslint no-unused-expressions: "off"*/ | ||
entity.type; | ||
test('should determine modifier of block', t => { | ||
const entityName = new BemEntityName({ block: 'block', mod: 'mod' }); | ||
|
||
t.truthy(t.context.stub.calledWith({ block: 'block', elem: 'elem' })); | ||
t.is(entityName.type, 'blockMod'); | ||
}); | ||
|
||
test('should use `naming.typeOf()` for block modifier', t => { | ||
const entity = new t.context.BemEntityName({ block: 'block', modName: 'mod', modVal: 'val' }); | ||
test('should determine elem', t => { | ||
const entityName = new BemEntityName({ block: 'block', elem: 'elem' }); | ||
|
||
t.is(entityName.type, 'elem'); | ||
}); | ||
|
||
/*eslint no-unused-expressions: "off"*/ | ||
entity.type; | ||
test('should determine modifier of element', t => { | ||
const entityName = new BemEntityName({ block: 'block', elem: 'elem', mod: 'mod' }); | ||
|
||
t.truthy(t.context.stub.calledWith({ block: 'block', modName: 'mod', modVal: 'val' })); | ||
t.is(entityName.type, 'elemMod'); | ||
}); | ||
|
||
test('should use naming.typeOf() for element modifier', t => { | ||
const entity = new t.context.BemEntityName({ block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' }); | ||
test('should cache type value', t => { | ||
const entity = new BemEntityName({ block: 'block' }); | ||
|
||
/*eslint no-unused-expressions: "off"*/ | ||
entity.type; | ||
entity.type; // eslint-disable-line no-unused-expressions | ||
|
||
t.truthy(t.context.stub.calledWith({ block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' })); | ||
t.is(entity._type, 'block'); | ||
}); | ||
|
||
test('should cache type value', t => { | ||
const entity = new t.context.BemEntityName({ block: 'block' }); | ||
test('should get type from cache', t => { | ||
const entity = new BemEntityName({ block: 'block' }); | ||
|
||
/*eslint no-unused-expressions: "off"*/ | ||
entity.type; | ||
entity.type; | ||
entity._type = 'fake'; | ||
|
||
t.is(t.context.stub.callCount, 1); | ||
t.is(entity.type, 'fake'); | ||
}); |