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 #338 from stampit-org/stamp-name
Add another non-spec metadata - "name" to change factory name
- Loading branch information
Showing
3 changed files
with
57 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import test from 'tape'; | ||
import stampit from '../src/stampit'; | ||
|
||
try { | ||
const f = Object.defineProperties( | ||
() => {}, | ||
{ name: { value: 'test' } } | ||
); | ||
|
||
if (f.name === 'test') { | ||
// Here we are sure that the environment supports function name change (ES6) | ||
|
||
test('name metadata can be set', (t) => { | ||
const stamp = stampit({ | ||
name: 'MyFactory' | ||
}); | ||
|
||
t.equal(stamp.name, 'MyFactory', | ||
'Should produce stamp with non-default name'); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('name metadata is inherited', (t) => { | ||
const stamp = stampit({ | ||
name: 'MyFactory' | ||
}); | ||
const derived = stamp.compose({ staticPropertyDescriptors: { value: { x: 'whatever' } } }); | ||
|
||
t.equal(derived.name, 'MyFactory', | ||
'Should inherit name from previous stamp'); | ||
t.equal(derived.compose.staticPropertyDescriptors.value.x, 'whatever', | ||
'Should not loose other data'); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('name metadata can be overwritten', (t) => { | ||
const stamp = stampit({ | ||
name: 'MyFactory' | ||
}); | ||
const derived = stamp.compose({ name: 'SecondOne' }); | ||
|
||
t.equal(derived.name, 'SecondOne', | ||
'Should overwrite previous stamp name'); | ||
|
||
t.end(); | ||
}); | ||
} | ||
} catch (e) { | ||
// skip these tests in this environment | ||
} |