-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathduck-chai.js
49 lines (45 loc) · 1.29 KB
/
duck-chai.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(function (duckChai) {
"use strict";
// Module systems magic dance.
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
// NodeJS
module.exports = duckChai();
} else if (typeof define === "function" && define.amd) {
// AMD
define(["jquery"], function ($) {
return function (chai, utils) {
return duckChai(chai, utils, $);
};
});
} else {
// Other environment (usually <script> tag): plug in to global chai instance directly.
chai.use(duckChai());
}
}(function duckChai(chai, utils, $) {
var states = {
visible: function(obj){
return obj.isVisible();
},
hidden: function(obj){
return obj.isHidden();
},
focused: function(obj) {
return obj.isFocused();
},
disabled: function(obj){
return obj.isDisabled();
},
enabled: function(obj){
return obj.isEnabled();
},
removed: function(obj){
return obj.isRemoved();
}
};
$.each(states, function(stateName, stateObj){
chai.Assertion.addProperty(stateName, function () {
var elString = "dom.element('"+this._obj.selector+"')";
this.assert(stateObj(this._obj), 'expected '+elString+' to be '+stateName, 'expected '+elString+' to not be '+stateName);
});
});
}));