-
-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add evented tests * change naming order of tests to follow modules
- Loading branch information
1 parent
c036552
commit f1d3c9a
Showing
5 changed files
with
160 additions
and
126 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* global describe,it */ | ||
import { assert } from 'chai'; | ||
import { Evented } from '../src/js/evented'; | ||
|
||
describe('Evented', function() { | ||
const testEvent = new Evented(); | ||
let testOnTriggered = false; | ||
describe('on()', function(){ | ||
it('adds a new event binding', function(){ | ||
testEvent.on('testOn', () => testOnTriggered = true ); | ||
assert.ok(testEvent.bindings.testOn, 'custom event added'); | ||
}); | ||
}); | ||
|
||
describe('trigger()', function(){ | ||
it('triggers a created event', function(){ | ||
testEvent.trigger('testOn'); | ||
assert.ok(testOnTriggered, 'true is returned from event trigger'); | ||
}); | ||
}); | ||
|
||
describe('off()', function(){ | ||
it('removes an event binding', function(){ | ||
testEvent.off('testOn'); | ||
assert.notOk(testEvent.bindings.testOn, 'custom event removed'); | ||
}); | ||
|
||
it('does not remove uncreated events', function(){ | ||
assert.notOk(testEvent.off('testBlank'), 'returns false for non created events'); | ||
}); | ||
}); | ||
|
||
describe('once()', function(){ | ||
it('adds a new event binding that only triggers once', function(){ | ||
testEvent.once('testOnce', () => true ); | ||
testEvent.trigger('testOnce') | ||
assert.ok(testEvent.bindings.testOnce, 'custom event removed after one trigger'); | ||
}); | ||
}); | ||
}); |
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