-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME
executable file
·62 lines (50 loc) · 2.41 KB
/
README
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
50
51
52
53
54
55
56
57
58
59
60
61
62
describe("js-spec", function() { with(this) {
it("should pass when doing simple comparisons", function() {
(1).should( equal(1) );
(1).should( be_less_than(2) );
(1).should( be_greater_than(0) );
(1).should_not( equal(2) );
(1).should_not( be(1) ); // 'be' checks if it's the same object
});
it("should pass when checking if a value is within a delta of another", function() {
// first argument is the target, second one the maximum allowed difference between both numbers
(1.0).should( be_close(1.05, 0.1) );
(1.0).should_not( be_close(1.5, 0.1) );
});
it("should pass when checking if a method changes an object", function() {
[1, 2, 3, 4].should_not( change("length").in_response_to("size") );
// the next example would also pass if you changed 'to(3)' to 'from(4)' or 'by(-1)'
[1, 2, 3, 4].should( change("length").to(3).in_response_to("pop") );
// it also works for functions, and you can even pass parameters to them:
[1, 2, 3, 4].should( change("first").to(0).in_response_to("unshift", 0) );
});
it("should pass when checking how many elements has an enumerable", function() {
$("some_container").should( have(1, "childElements") );
[1, 2, 3, 4].should( have(2, "slice", 0, 2) ); // equivalent to [1, 2, 3, 4].slice(0, 2).length.should( equal(2) )
$("some_container").down("span").should_not( have_at_least(1, "childElements") );
});
it("should pass when asking if an enumerable includes some elements", function() {
[1, 2, 3, 4].should( include(1, 2) );
[1, 2, 3, 4].should_not( include(0) );
})
it("should match strings to regexps", function() {
"to be or not to be".should_not( match(/^2b|[^b]{2}$/) );
"Something".should( match(/^[Ss]/) );
});
it("should match DOM nodes to selectors correctly", function() {
$("some_container").should( match("#some_container") );
$("some_container").down(".something").should( match("#some_container .something") );
});
it("should pass when asking if an object responds to a method", function() {
[1, 2, 3].should( respond_to("size") );
"string".should_not( respond_to("asdfg") );
});
it("should pass when asking if an object satisfies a block", function() {
[1, 2, 3].should( satisfy(function(list) {
return list.length > 2;
}));
"string".should_not( satisfy(function(word) {
return word.startsWith("cuack");
}));
});
}});