This repository was archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathcoffee.spec.js
More file actions
53 lines (42 loc) · 1.47 KB
/
coffee.spec.js
File metadata and controls
53 lines (42 loc) · 1.47 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
// TODO(vojta): add an API for exporting these APIs to global namespace.
import {use, inject} from '../../src/testing';
import {CoffeeMaker} from '../coffee/coffee_maker';
import {Heater} from '../coffee/heater';
import {Pump} from '../coffee/pump';
import {MockHeater, DummyHeater} from './mocks';
describe('simple mocking in beforeEach', function() {
// Use DummyHeater, which has @Provide(Heater) annotation.
beforeEach(use(DummyHeater));
it('should brew', inject(CoffeeMaker, function(cm) {
cm.brew();
}));
});
describe('more mocking in beforeEach', function() {
beforeEach(function() {
// Use MockHeater, instead of Heater.
use(MockHeater).as(Heater);
// Inlined mock - if it's not a function/class, the actual value is used.
use({
pump: jasmine.createSpy('pump')
}).as(Pump);
});
it('should brew', inject(CoffeeMaker, Heater, Pump, function(cm, heater, pump) {
cm.brew();
expect(heater.on).toHaveBeenCalled();
expect(pump.pump).toHaveBeenCalled();
}));
});
describe('mocking inside it', function() {
it('should brew', function() {
// Both use().as() and inject() can be also used inside it().
use(MockHeater).as(Heater);
inject(CoffeeMaker, function(cm, heater) {
cm.brew();
});
// There can be multiple use() or inject() calls.
// However, you can't use use() after you already called inject().
inject(Heater, function(heater) {
expect(heater.on).toHaveBeenCalled();
});
});
});