This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
ajax-get-test.js
65 lines (49 loc) · 1.62 KB
/
ajax-get-test.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
60
61
62
63
64
import {
describe,
beforeEach,
afterEach,
it
} from 'mocha';
import { expect } from 'chai';
import destroyApp from 'dummy/tests/helpers/destroy-app';
import startApp from 'dummy/tests/helpers/start-app';
import Pretender from 'pretender';
import { jsonFactory as json } from 'dummy/tests/helpers/json';
describe('Acceptance | ajax-get component', function() {
beforeEach(function() {
this.server = new Pretender();
this.application = startApp();
});
afterEach(function() {
this.server.shutdown();
destroyApp(this.application);
});
it('waits for a route with async widget', function() {
const PAYLOAD = [{ title: 'Foo' }, { title: 'Bar' }, { title: 'Baz' }];
this.server.get('/posts', json(200, PAYLOAD), 300);
visit('/');
andThen(function() {
expect(currentURL()).to.equal('/');
expect(find('.ajax-get').length).to.equal(1);
});
click('button:contains(Load Data)');
andThen(function() {
expect(find('.ajax-get li:eq(0)').text()).to.equal('Foo');
expect(find('.ajax-get li:eq(1)').text()).to.equal('Bar');
expect(find('.ajax-get li:eq(2)').text()).to.equal('Baz');
});
});
it('catches errors before they bubble to the console', function() {
const errorMessage = 'Not Found';
this.server.get('/posts', json(404, errorMessage), 300);
visit('/');
andThen(function() {
expect(currentURL()).to.equal('/');
expect(find('.ajax-get').length === 1).to.be.ok;
});
click('button:contains(Load Data)');
andThen(function() {
expect(find('.ajax-get .error').text().trim()).to.equal(errorMessage);
});
});
});