forked from jsmapr1/simplifying-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem.spec.js
More file actions
63 lines (52 loc) · 1.59 KB
/
Copy pathproblem.spec.js
File metadata and controls
63 lines (52 loc) · 1.59 KB
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
import expect from 'expect';
import sinon from 'sinon';
import * as routing from './routing';
import * as taxService from './taxService';
import { formatPrice } from './problem';
// START:tests
describe('format price', () => {
const userElement = {
innerHTML: 'Aaron Cometbus',
};
const totalElement = {
innerHTML: '',
};
const document = { // <label id="test.document" />
getElementById: id => {
if (id === 'user') {
return userElement;
}
if (id === 'total') {
return totalElement;
}
return null;
},
};
global.document = document;
let taxStub;
beforeEach(() => {
taxStub = sinon.stub(taxService, 'getTaxInformation'); // <label id="test.stub" />
});
afterEach(() => {
totalElement.innerHTML = ''; // <label id="test.reset" />
taxStub.restore();
});
it('should redirect if no location', () => {
sinon.spy(routing, 'redirect'); // <label id="test.spy" />
formatPrice({}, undefined);
expect(routing.redirect.called).toEqual(true);
});
it('should return plus tax if no tax info', () => {
taxStub.returns(null); // <label id="test.stub2" />
formatPrice({ price: 30, location: 'Oklahoma' });
const message = 'Aaron Cometbus your total is: 30 plus tax.';
expect(totalElement.innerHTML).toEqual(message);
});
it('should return plus tax information', () => {
taxStub.returns(0.1);
formatPrice({ price: 30, location: 'Oklahoma' });
const message = 'Aaron Cometbus your total is: 30 plus $3 in taxes.';
expect(totalElement.innerHTML).toEqual(message);
});
// END:tests
});