-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeatherModelTests.js
59 lines (54 loc) · 1.98 KB
/
WeatherModelTests.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
50
51
52
53
54
55
56
57
58
59
describe("Weather Finder", function() {
describe("Weather Model", function() {
beforeEach(function() {
$.mockjaxClear();
});
it("Makes an AJAX request to the weather service to find it's raining "
+ "in Aberystwyth", function() {
var successResponse = null;
var failResponse = null;
runs(function() {
$.mockjax({
url: "http://api.openweathermap.org/data/2.5/weather",
data: {
q: "Aberystwyth, Wales"
},
responseTime: 0,
status: 500,
responseText: {
"weather": [{
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"main":{
"temp":285.382
},
"name": "Aberystwyth"
}
});
var weatherModel = new WeatherModel();
weatherModel.getWeather(
"Aberystwyth, Wales",
function(response) {
successResponse = response;
},
function(what, happened, here) {
failResponse = {
what: what,
happened: happened,
here: here
};
}
);
});
waitsFor(function() {
return successResponse != null || failResponse != null;
}, "Expecting a response from the AJAX request", 1000);
runs(function() {
expect(failResponse).toBe(null);
expect(successResponse.weather[0].main).toBe("Rain");
});
});
});
});