Skip to content
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

Added element id to logger; Addresses #342. #347

Merged
merged 1 commit into from
May 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ define(

function elemToString(elem) {
var tagStr = elem.tagName ? elem.tagName.toLowerCase() : elem.toString();
var idStr = elem.id ? '#' + (elem.id) : '';
var classStr = elem.className ? '.' + (elem.className) : '';
var result = tagStr + classStr;
var result = tagStr + idStr + classStr;
return elem.tagName ? ['\'', '\''].join(result) : result;
}

Expand Down
16 changes: 8 additions & 8 deletions test/spec/logger_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ define(['lib/component', 'lib/debug'], function(defineComponent, debug) {

var instance;
var Component;
var div = $('<div class="myDiv"></div>').appendTo('body')[0];
var div = $('<div id="myDiv" class="myDiv"></div>').appendTo('body')[0];
var span = $('<span class="mySpan"></span>').appendTo('body')[0];

describe('(Core) logger', function () {
Expand All @@ -30,7 +30,7 @@ define(['lib/component', 'lib/debug'], function(defineComponent, debug) {
it('logs trigger for default node', function () {
spyOn(console, 'info');
instance.trigger('click');
expect(console.info).toHaveBeenCalledWith('->', 'trigger', '[click]', '\'div.myDiv\'', '');
expect(console.info).toHaveBeenCalledWith('->', 'trigger', '[click]', '\'div#myDiv.myDiv\'', '');
});

it('logs trigger for custom node', function () {
Expand All @@ -43,13 +43,13 @@ define(['lib/component', 'lib/debug'], function(defineComponent, debug) {
var data = {a:2};
spyOn(console, 'info');
instance.trigger('click', data);
expect(console.info).toHaveBeenCalledWith('->', 'trigger', '[click]', data, '\'div.myDiv\'', '');
expect(console.info).toHaveBeenCalledWith('->', 'trigger', '[click]', data, '\'div#myDiv.myDiv\'', '');
});

it('logs trigger with event object', function () {
spyOn(console, 'info');
instance.trigger({type:'click'});
expect(console.info).toHaveBeenCalledWith('->', 'trigger', '[click]', '\'div.myDiv\'', '');
expect(console.info).toHaveBeenCalledWith('->', 'trigger', '[click]', '\'div#myDiv.myDiv\'', '');
});

it('logs trigger for custom node with event object', function () {
Expand All @@ -62,7 +62,7 @@ define(['lib/component', 'lib/debug'], function(defineComponent, debug) {
var data = {a:2};
spyOn(console, 'info');
instance.trigger({type:'click'}, data);
expect(console.info).toHaveBeenCalledWith('->', 'trigger', '[click]', data, '\'div.myDiv\'', '');
expect(console.info).toHaveBeenCalledWith('->', 'trigger', '[click]', data, '\'div#myDiv.myDiv\'', '');
});

it('logs trigger for custom node with event object and payload', function () {
Expand All @@ -77,7 +77,7 @@ define(['lib/component', 'lib/debug'], function(defineComponent, debug) {
it('logs on events for default node', function () {
spyOn(console, 'info');
instance.on('start', instance.handler);
expect(console.info).toHaveBeenCalledWith('<-', 'on', '[start]', '\'div.myDiv\'', '');
expect(console.info).toHaveBeenCalledWith('<-', 'on', '[start]', '\'div#myDiv.myDiv\'', '');
});

it('logs on events for custom node', function () {
Expand All @@ -91,13 +91,13 @@ define(['lib/component', 'lib/debug'], function(defineComponent, debug) {
it('logs off events for default node and no handler', function () {
spyOn(console, 'info');
instance.off('start');
expect(console.info).toHaveBeenCalledWith('x ', 'off', '[start]', '\'div.myDiv\'', '');
expect(console.info).toHaveBeenCalledWith('x ', 'off', '[start]', '\'div#myDiv.myDiv\'', '');
});

it('logs off events for default node with handler', function () {
spyOn(console, 'info');
instance.off('start', instance.handler);
expect(console.info).toHaveBeenCalledWith('x ', 'off', '[start]', '\'div.myDiv\'', '');
expect(console.info).toHaveBeenCalledWith('x ', 'off', '[start]', '\'div#myDiv.myDiv\'', '');
});

it('logs off events for custom node with handler', function () {
Expand Down