Skip to content

Commit

Permalink
changed type compare to instanceof and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Hall committed Feb 23, 2016
1 parent afe3c41 commit 7e92d65
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shared/helpers/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function getClientPlaceholder(viewName, viewOptions, Handlebars) {
// create a list of data attributes
var attrString = _.inject(viewOptions, function(memo, value, key) {
if (_.isArray(value) || _.isObject(value)) {
if (key === '_block' && value.contructor === Handlebars.SafeString) {
if (key === '_block' && value instanceof Handlebars.SafeString) {
value = value.string;
} else {
value = JSON.stringify(value);
Expand Down
16 changes: 16 additions & 0 deletions test/shared/helpers/view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ describe('view', function () {
'<div data-render="true" data-generic_object="{&quot;a&quot;:1,&quot;b&quot;:2,&quot;c&quot;:3}" data-fetch_summary="{}" data-view="test"></div>'
);
});

context('when the key is _block and is of type Handlebars.SafeString', function () {
it('extracts the string correctly', function () {
var html = '<div>something</div>',
result = subject.call({
_app: app()
}, 'test', {
hash: {
_block: new Handlebars.SafeString(html)
}
});
expect(result.string).to.eq(
'<div data-render="true" data-_block="&lt;div&gt;something&lt;/div&gt;" data-fetch_summary="{}" data-view="test"></div>'
);
});
});
});
});
});

0 comments on commit 7e92d65

Please sign in to comment.