Skip to content
This repository was archived by the owner on Feb 4, 2018. It is now read-only.

Commit 2b87fbd

Browse files
author
blond
committed
test(scope): add scope field
1 parent ae9c83f commit 2b87fbd

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

test/scope.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import test from 'ava';
2+
3+
import BemEntityName from '../lib/entity-name';
4+
5+
test('should return scope of block', t => {
6+
const entityName = new BemEntityName({ block: 'block' });
7+
8+
t.is(entityName.scope, null);
9+
});
10+
11+
test('should return scope of block modifier', t => {
12+
const entityName = new BemEntityName({ block: 'block', mod: 'mod' });
13+
14+
t.deepEqual(entityName.scope.valueOf(), { block: 'block' });
15+
});
16+
17+
test('should return same scope for simple and complex mod', t => {
18+
const simpleModName = new BemEntityName({ block: 'block', mod: 'mod' });
19+
const complexModName = new BemEntityName({ block: 'block', mod: { name: 'mod', val: 'val' } });
20+
21+
t.deepEqual(simpleModName.scope, complexModName.scope);
22+
});
23+
24+
test('should return scope of element', t => {
25+
const entityName = new BemEntityName({ block: 'block', elem: 'elem' });
26+
27+
t.deepEqual(entityName.scope.valueOf(), { block: 'block' });
28+
});
29+
30+
test('should return scope of element modifier', t => {
31+
const entityName = new BemEntityName({ block: 'block', elem: 'elem', mod: 'mod' });
32+
33+
t.deepEqual(entityName.scope.valueOf(), { block: 'block', elem: 'elem' });
34+
});
35+
36+
test('should cache scope value', t => {
37+
const entity = new BemEntityName({ block: 'block', elem: 'elem' });
38+
39+
entity.scope; // eslint-disable-line no-unused-expressions
40+
41+
t.deepEqual(entity._scope.valueOf(), { block: 'block' });
42+
});
43+
44+
test('should get scope from cache', t => {
45+
const entity = new BemEntityName({ block: 'block', elem: 'elem' });
46+
47+
entity._scope = 'fake';
48+
49+
t.is(entity.scope, 'fake');
50+
});

0 commit comments

Comments
 (0)