-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Adding ng-jq functionality, the ability to force jqLite or any other lib... #10761
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -615,6 +615,94 @@ describe('angular', function() { | |
}); | ||
|
||
|
||
describe('jq', function() { | ||
var element; | ||
|
||
beforeEach(function() { | ||
element = document.createElement('html'); | ||
}); | ||
|
||
afterEach(function() { | ||
delete jq.name_; | ||
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. Just being curious: Why first set it to undefined and then delete it ? 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. @gkalpak Sorry, force of habit from a time when delete was buggy in javascript. I guess that's fixed now since Angular supports IE 9 and above. |
||
}); | ||
|
||
it('should return undefined when jq is not set, no jQuery found (the default)', function() { | ||
expect(jq()).toBe(undefined); | ||
}); | ||
|
||
it('should return empty string when jq is enabled manually via [ng-jq] with empty string', function() { | ||
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. I don't get the purpose of the functionality tested here :( 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. It's to differentiate between an Not the prettiest APIs of all, I agree, but it's used just in one place really so I didn't picked at it. 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. |
||
element.setAttribute('ng-jq', ''); | ||
spyOn(document, 'querySelector').andCallFake(function(selector) { | ||
if (selector === '[ng-jq]') return element; | ||
}); | ||
expect(jq()).toBe(''); | ||
}); | ||
|
||
it('should return empty string when jq is enabled manually via [data-ng-jq] with empty string', function() { | ||
element.setAttribute('data-ng-jq', ''); | ||
spyOn(document, 'querySelector').andCallFake(function(selector) { | ||
if (selector === '[data-ng-jq]') return element; | ||
}); | ||
expect(jq()).toBe(''); | ||
expect(document.querySelector).toHaveBeenCalledWith('[data-ng-jq]'); | ||
}); | ||
|
||
it('should return empty string when jq is enabled manually via [x-ng-jq] with empty string', function() { | ||
element.setAttribute('x-ng-jq', ''); | ||
spyOn(document, 'querySelector').andCallFake(function(selector) { | ||
if (selector === '[x-ng-jq]') return element; | ||
}); | ||
expect(jq()).toBe(''); | ||
expect(document.querySelector).toHaveBeenCalledWith('[x-ng-jq]'); | ||
}); | ||
|
||
it('should return empty string when jq is enabled manually via [ng:jq] with empty string', function() { | ||
element.setAttribute('ng:jq', ''); | ||
spyOn(document, 'querySelector').andCallFake(function(selector) { | ||
if (selector === '[ng\\:jq]') return element; | ||
}); | ||
expect(jq()).toBe(''); | ||
expect(document.querySelector).toHaveBeenCalledWith('[ng\\:jq]'); | ||
}); | ||
|
||
it('should return "jQuery" when jq is enabled manually via [ng-jq] with value "jQuery"', function() { | ||
element.setAttribute('ng-jq', 'jQuery'); | ||
spyOn(document, 'querySelector').andCallFake(function(selector) { | ||
if (selector === '[ng-jq]') return element; | ||
}); | ||
expect(jq()).toBe('jQuery'); | ||
expect(document.querySelector).toHaveBeenCalledWith('[ng-jq]'); | ||
}); | ||
|
||
it('should return "jQuery" when jq is enabled manually via [data-ng-jq] with value "jQuery"', function() { | ||
element.setAttribute('data-ng-jq', 'jQuery'); | ||
spyOn(document, 'querySelector').andCallFake(function(selector) { | ||
if (selector === '[data-ng-jq]') return element; | ||
}); | ||
expect(jq()).toBe('jQuery'); | ||
expect(document.querySelector).toHaveBeenCalledWith('[data-ng-jq]'); | ||
}); | ||
|
||
it('should return "jQuery" when jq is enabled manually via [x-ng-jq] with value "jQuery"', function() { | ||
element.setAttribute('x-ng-jq', 'jQuery'); | ||
spyOn(document, 'querySelector').andCallFake(function(selector) { | ||
if (selector === '[x-ng-jq]') return element; | ||
}); | ||
expect(jq()).toBe('jQuery'); | ||
expect(document.querySelector).toHaveBeenCalledWith('[x-ng-jq]'); | ||
}); | ||
|
||
it('should return "jQuery" when jq is enabled manually via [ng:jq] with value "jQuery"', function() { | ||
element.setAttribute('ng:jq', 'jQuery'); | ||
spyOn(document, 'querySelector').andCallFake(function(selector) { | ||
if (selector === '[ng\\:jq]') return element; | ||
}); | ||
expect(jq()).toBe('jQuery'); | ||
expect(document.querySelector).toHaveBeenCalledWith('[ng\\:jq]'); | ||
}); | ||
}); | ||
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. I believe there should be also some tests verifying the correct behaviour when 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. @gkalpak I agree, but when I tried to do said test, it would fail all other tests since the real jQuery was being disrupted, which is used in other tests. I tried using the angularInit tests as an example since I need to test out the bindJquery function. Any direction would be appreciated. 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. @mboudreau: I was thinking something "non-disruptive". Maybe verifying what But I don't feel too strongly about it :) |
||
|
||
|
||
describe('parseKeyValue', function() { | ||
it('should parse a string into key-value pairs', function() { | ||
expect(parseKeyValue('')).toEqual({}); | ||
|
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.
jsHint will catch it (see my other comments), you can search for
csp
and see where it needs to be added to pass jsHint tests.