summaryrefslogtreecommitdiffstats
path: root/test/helpers/fireSpec.js
blob: 5d5dcbb7a3da6285b660ffcc8294289ec603d2e7 (plain)
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
describe("Awesomplete.$.fire", function () {

	$.fixture("plain");

	subject(function () {
		return Awesomplete.$.fire.bind(Awesomplete.$, this.element);
	});

	def("element", function () { return $("#plain") });

	beforeEach(function () {
		spyOn(this.element, "dispatchEvent");
	});

	it("fires event once", function () {
		this.subject("click");
		expect(this.element.dispatchEvent.calls.count()).toEqual(1);
	});

	describe("fires different event types", function () {
		it("fires click event", function () {
			this.subject("click");
			expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ type: "click" }));
		});

		it("fires input event", function () {
			this.subject("input");
			expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ type: "input" }));
		});
	});

	describe("sets event properties", function () {
		it("makes cancelable event", function () {
			this.subject("click");
			expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ cancelable: true }));
		});

		it("can't make non cancelable event", function () {
			this.subject("click", { cancelable: false });
			expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ cancelable: true }));
		});

		it("makes event that bubbles", function () {
			this.subject("click");
			expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ bubbles: true }));
		});

		it("can't make event that does not bubble", function () {
			this.subject("click", { bubbles: false });
			expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ bubbles: true }));
		});

		it("sets properties on the event", function () {
			var properties = { text: "hello", preventDefault: $.noop };

			this.subject("click", properties);
			expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining(properties));
		});
	});
});