Skip to content

Commit

Permalink
Remove immediately invoked fn expression from jasmine-jquery
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Sobo committed Sep 19, 2015
1 parent a28dc08 commit ab5a560
Showing 1 changed file with 166 additions and 169 deletions.
335 changes: 166 additions & 169 deletions vendor/jasmine-jquery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function() {
'use strict'

jasmine.JQuery = function() {}

Expand All @@ -18,201 +18,198 @@ jasmine.JQuery.elementToString = function(element) {

jasmine.JQuery.matchersClass = {}

(function(){
var jQueryMatchers = {
toHaveClass: function(className) {
if (this.actual instanceof HTMLElement) {
return this.actual.classList.contains(className)
} else {
return this.actual.hasClass(className)
}
},

toBeVisible: function() {
if (this.actual instanceof HTMLElement) {
return this.actual.offsetWidth !== 0 || this.actual.offsetHeight !== 0
} else {
return this.actual.is(':visible')
}
},
var jQueryMatchers = {
toHaveClass: function(className) {
if (this.actual instanceof HTMLElement) {
return this.actual.classList.contains(className)
} else {
return this.actual.hasClass(className)
}
},

toBeHidden: function() {
if (this.actual instanceof HTMLElement) {
return this.actual.offsetWidth === 0 && this.actual.offsetHeight === 0
} else {
return this.actual.is(':hidden')
}
},
toBeVisible: function() {
if (this.actual instanceof HTMLElement) {
return this.actual.offsetWidth !== 0 || this.actual.offsetHeight !== 0
} else {
return this.actual.is(':visible')
}
},

toBeSelected: function() {
if (this.actual instanceof HTMLElement) {
return this.actual.selected
} else {
return this.actual.is(':selected')
}
},
toBeHidden: function() {
if (this.actual instanceof HTMLElement) {
return this.actual.offsetWidth === 0 && this.actual.offsetHeight === 0
} else {
return this.actual.is(':hidden')
}
},

toBeChecked: function() {
if (this.actual instanceof HTMLElement) {
return this.actual.checked
} else {
return this.actual.is(':checked')
}
},
toBeSelected: function() {
if (this.actual instanceof HTMLElement) {
return this.actual.selected
} else {
return this.actual.is(':selected')
}
},

toBeEmpty: function() {
if (this.actual instanceof HTMLElement) {
return this.actual.innerHTML === ''
} else {
return this.actual.is(':empty')
}
},
toBeChecked: function() {
if (this.actual instanceof HTMLElement) {
return this.actual.checked
} else {
return this.actual.is(':checked')
}
},

toExist: function() {
if (this.actual instanceof HTMLElement) {
return true
} else if (this.actual) {
return this.actual.size() > 0
} else {
return false
}
},

toHaveAttr: function(attributeName, expectedAttributeValue) {
var actualAttributeValue
if (this.actual instanceof HTMLElement) {
actualAttributeValue = this.actual.getAttribute(attributeName)
} else {
actualAttributeValue = this.actual.attr(attributeName)
}
toBeEmpty: function() {
if (this.actual instanceof HTMLElement) {
return this.actual.innerHTML === ''
} else {
return this.actual.is(':empty')
}
},

toExist: function() {
if (this.actual instanceof HTMLElement) {
return true
} else if (this.actual) {
return this.actual.size() > 0
} else {
return false
}
},

toHaveAttr: function(attributeName, expectedAttributeValue) {
var actualAttributeValue
if (this.actual instanceof HTMLElement) {
actualAttributeValue = this.actual.getAttribute(attributeName)
} else {
actualAttributeValue = this.actual.attr(attributeName)
}

return hasProperty(actualAttributeValue, expectedAttributeValue)
},
return hasProperty(actualAttributeValue, expectedAttributeValue)
},

toHaveId: function(id) {
if (this.actual instanceof HTMLElement) {
return this.actual.getAttribute('id') == id
} else {
return this.actual.attr('id') == id
}
},

toHaveHtml: function(html) {
var actualHTML
if (this.actual instanceof HTMLElement) {
actualHTML = this.actual.innerHTML
} else {
actualHTML = this.actual.html()
}
toHaveId: function(id) {
if (this.actual instanceof HTMLElement) {
return this.actual.getAttribute('id') == id
} else {
return this.actual.attr('id') == id
}
},

toHaveHtml: function(html) {
var actualHTML
if (this.actual instanceof HTMLElement) {
actualHTML = this.actual.innerHTML
} else {
actualHTML = this.actual.html()
}

return actualHTML == jasmine.JQuery.browserTagCaseIndependentHtml(html)
},
return actualHTML == jasmine.JQuery.browserTagCaseIndependentHtml(html)
},

toHaveText: function(text) {
var actualText
if (this.actual instanceof HTMLElement) {
actualText = this.actual.textContent
} else {
actualText = this.actual.text()
}
toHaveText: function(text) {
var actualText
if (this.actual instanceof HTMLElement) {
actualText = this.actual.textContent
} else {
actualText = this.actual.text()
}

if (text && typeof text.test === 'function') {
return text.test(actualText)
} else {
return actualText == text
}
},
if (text && typeof text.test === 'function') {
return text.test(actualText)
} else {
return actualText == text
}
},

toHaveValue: function(value) {
if (this.actual instanceof HTMLElement) {
return this.actual.value == value
} else {
return this.actual.val() == value
}
},
toHaveValue: function(value) {
if (this.actual instanceof HTMLElement) {
return this.actual.value == value
} else {
return this.actual.val() == value
}
},

toHaveData: function(key, expectedValue) {
if (this.actual instanceof HTMLElement) {
return hasProperty(this.actual.dataset[key], expectedValue)
} else {
return hasProperty(this.actual.data(key), expectedValue)
}
},
toHaveData: function(key, expectedValue) {
if (this.actual instanceof HTMLElement) {
return hasProperty(this.actual.dataset[key], expectedValue)
} else {
return hasProperty(this.actual.data(key), expectedValue)
}
},

toMatchSelector: function(selector) {
if (this.actual instanceof HTMLElement) {
return this.actual.matches(selector)
} else {
return this.actual.is(selector)
}
},
toMatchSelector: function(selector) {
if (this.actual instanceof HTMLElement) {
return this.actual.matches(selector)
} else {
return this.actual.is(selector)
}
},

toContain: function(selector) {
if (this.actual instanceof HTMLElement) {
return !!this.actual.querySelector(selector)
} else {
return this.actual.find(selector).size() > 0
}
},
toContain: function(selector) {
if (this.actual instanceof HTMLElement) {
return !!this.actual.querySelector(selector)
} else {
return this.actual.find(selector).size() > 0
}
},

toBeDisabled: function(selector){
if (this.actual instanceof HTMLElement) {
return this.actual.disabled
} else {
return this.actual.is(':disabled')
}
},

// tests the existence of a specific event binding
toHandle: function(eventName) {
var events = this.actual.data("events")
return events && events[eventName].length > 0
},

// tests the existence of a specific event binding + handler
toHandleWith: function(eventName, eventHandler) {
var stack = this.actual.data("events")[eventName]
var i
for (i = 0; i < stack.length; i++) {
if (stack[i].handler == eventHandler) {
return true
}
toBeDisabled: function(selector){
if (this.actual instanceof HTMLElement) {
return this.actual.disabled
} else {
return this.actual.is(':disabled')
}
},

// tests the existence of a specific event binding
toHandle: function(eventName) {
var events = this.actual.data("events")
return events && events[eventName].length > 0
},

// tests the existence of a specific event binding + handler
toHandleWith: function(eventName, eventHandler) {
var stack = this.actual.data("events")[eventName]
var i
for (i = 0; i < stack.length; i++) {
if (stack[i].handler == eventHandler) {
return true
}
return false
}
return false
}
}

var hasProperty = function(actualValue, expectedValue) {
if (expectedValue === undefined) {
return actualValue !== undefined
}
return actualValue == expectedValue
var hasProperty = function(actualValue, expectedValue) {
if (expectedValue === undefined) {
return actualValue !== undefined
}
return actualValue == expectedValue
}

var bindMatcher = function(methodName) {
var builtInMatcher = jasmine.Matchers.prototype[methodName]

jasmine.JQuery.matchersClass[methodName] = function() {
if (this.actual && this.actual.jquery || this.actual instanceof HTMLElement) {
var result = jQueryMatchers[methodName].apply(this, arguments)
this.actual = jasmine.JQuery.elementToString(this.actual)
return result
}
var bindMatcher = function(methodName) {
var builtInMatcher = jasmine.Matchers.prototype[methodName]

if (builtInMatcher) {
return builtInMatcher.apply(this, arguments)
}
jasmine.JQuery.matchersClass[methodName] = function() {
if (this.actual && this.actual.jquery || this.actual instanceof HTMLElement) {
var result = jQueryMatchers[methodName].apply(this, arguments)
this.actual = jasmine.JQuery.elementToString(this.actual)
return result
}

return false
if (builtInMatcher) {
return builtInMatcher.apply(this, arguments)
}
}

for(var methodName in jQueryMatchers) {
bindMatcher(methodName)
return false
}
})()
}

for(var methodName in jQueryMatchers) {
bindMatcher(methodName)
}

beforeEach(function() {
this.addMatchers(jasmine.JQuery.matchersClass)
})
})()

0 comments on commit ab5a560

Please sign in to comment.