-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix .add()
无法覆盖同名模板的问题,并增加相应单元测试
#20
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,10 @@ void function () { | |
'</ul>' | ||
].join('\n') | ||
|
||
//compiledTemplate | ||
var fn1 = _.template(templateCode1) | ||
var fn2 = _.template(templateCode2) | ||
|
||
//template data | ||
var templateData1 = {text: HELLO} | ||
var templateData2 = [ | ||
|
@@ -328,18 +332,31 @@ void function () { | |
expect(_cacheTemplate).to.deep.equal(data) | ||
expect(_cacheCompiledTemplate).to.deep.equal({}) | ||
}) | ||
it('overwrites while adding existed template id', function () { | ||
it('overwrites template while adding existed template id', function () { | ||
expect(_cacheTemplate).to.deep.equal({}) | ||
data = {} | ||
|
||
template.add(TEMPLATE_ID_1, templateCode1) | ||
data[TEMPLATE_ID_1] = templateCode1 | ||
expect(_cacheTemplate).to.deep.equal(data) | ||
|
||
template.add(TEMPLATE_ID_2, templateCode2) | ||
data[TEMPLATE_ID_2] = templateCode2 | ||
template.add(TEMPLATE_ID_1, templateCode2) | ||
data[TEMPLATE_ID_1] = templateCode2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 原来的测试代码写错了? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我觉得写错了,我认为应该这么测试:add一次id为TEMPLATE_ID_1的模板templateCode1,然后再add一次同名的模板templateCode2, data是正确的,然后比较_cacheTemplate和data是否一致。 |
||
expect(_cacheTemplate).to.deep.equal(data) | ||
}) | ||
it('overwrites compiledTemplate while adding existed template id', function () { | ||
expect(_cacheCompiledTemplate).to.deep.equal({}) | ||
|
||
template.add(TEMPLATE_ID_1, templateCode1) | ||
template.render(TEMPLATE_ID_1, templateData1) | ||
expect(_cacheCompiledTemplate[TEMPLATE_ID_1].source).to.equal(fn1.source) | ||
|
||
template.add(TEMPLATE_ID_1, templateCode2) | ||
expect(_cacheCompiledTemplate[TEMPLATE_ID_1]).to.equal(null) | ||
template.render(TEMPLATE_ID_1, templateData2) | ||
expect(_cacheCompiledTemplate[TEMPLATE_ID_1]).to.be.a('function') | ||
expect(_cacheCompiledTemplate[TEMPLATE_ID_1].source).to.equal(fn2.source) | ||
}) | ||
it('does nothing if missing template code as second param', function () { | ||
expect(_cacheTemplate).to.deep.equal({}) | ||
template.add('foo') | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
所有写在
/** DEBUG_INFO_START **/
和/** DEBUG_INFO_END **/
之间的代码在发布文件中会被清除。