-
-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove references to window from headless
- Loading branch information
Showing
29 changed files
with
127 additions
and
154 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,60 @@ | ||
/*global mock */ | ||
|
||
const container = {}; | ||
|
||
describe("The _converse Event Emitter", function() { | ||
|
||
it("allows you to subscribe to emitted events", mock.initConverse((_converse) => { | ||
window.callback = function () {}; | ||
spyOn(window, 'callback'); | ||
_converse.on('connected', window.callback); | ||
container.callback = function () {}; | ||
spyOn(container, 'callback'); | ||
_converse.on('connected', container.callback); | ||
_converse.api.trigger('connected'); | ||
expect(window.callback).toHaveBeenCalled(); | ||
expect(container.callback).toHaveBeenCalled(); | ||
_converse.api.trigger('connected'); | ||
expect(window.callback.calls.count(), 2); | ||
expect(container.callback.calls.count(), 2); | ||
_converse.api.trigger('connected'); | ||
expect(window.callback.calls.count(), 3); | ||
expect(container.callback.calls.count(), 3); | ||
})); | ||
|
||
it("allows you to listen once for an emitted event", mock.initConverse((_converse) => { | ||
window.callback = function () {}; | ||
spyOn(window, 'callback'); | ||
_converse.once('connected', window.callback); | ||
container.callback = function () {}; | ||
spyOn(container, 'callback'); | ||
_converse.once('connected', container.callback); | ||
_converse.api.trigger('connected'); | ||
expect(window.callback).toHaveBeenCalled(); | ||
expect(container.callback).toHaveBeenCalled(); | ||
_converse.api.trigger('connected'); | ||
expect(window.callback.calls.count(), 1); | ||
expect(container.callback.calls.count(), 1); | ||
_converse.api.trigger('connected'); | ||
expect(window.callback.calls.count(), 1); | ||
expect(container.callback.calls.count(), 1); | ||
})); | ||
|
||
it("allows you to stop listening or subscribing to an event", mock.initConverse((_converse) => { | ||
window.callback = function () {}; | ||
window.anotherCallback = function () {}; | ||
window.neverCalled = function () {}; | ||
container.callback = function () {}; | ||
container.anotherCallback = function () {}; | ||
container.neverCalled = function () {}; | ||
|
||
spyOn(window, 'callback'); | ||
spyOn(window, 'anotherCallback'); | ||
spyOn(window, 'neverCalled'); | ||
_converse.on('connected', window.callback); | ||
_converse.on('connected', window.anotherCallback); | ||
spyOn(container, 'callback'); | ||
spyOn(container, 'anotherCallback'); | ||
spyOn(container, 'neverCalled'); | ||
_converse.on('connected', container.callback); | ||
_converse.on('connected', container.anotherCallback); | ||
|
||
_converse.api.trigger('connected'); | ||
expect(window.callback).toHaveBeenCalled(); | ||
expect(window.anotherCallback).toHaveBeenCalled(); | ||
expect(container.callback).toHaveBeenCalled(); | ||
expect(container.anotherCallback).toHaveBeenCalled(); | ||
|
||
_converse.off('connected', window.callback); | ||
_converse.off('connected', container.callback); | ||
|
||
_converse.api.trigger('connected'); | ||
expect(window.callback.calls.count(), 1); | ||
expect(window.anotherCallback.calls.count(), 2); | ||
expect(container.callback.calls.count(), 1); | ||
expect(container.anotherCallback.calls.count(), 2); | ||
|
||
_converse.once('connected', window.neverCalled); | ||
_converse.off('connected', window.neverCalled); | ||
_converse.once('connected', container.neverCalled); | ||
_converse.off('connected', container.neverCalled); | ||
|
||
_converse.api.trigger('connected'); | ||
expect(window.callback.calls.count(), 1); | ||
expect(window.anotherCallback.calls.count(), 3); | ||
expect(window.neverCalled).not.toHaveBeenCalled(); | ||
expect(container.callback.calls.count(), 1); | ||
expect(container.anotherCallback.calls.count(), 3); | ||
expect(container.neverCalled).not.toHaveBeenCalled(); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.