mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-24 03:57:08 -04:00
Publish tests.
This commit is contained in:
parent
5a8ecd593d
commit
c396800dfa
40 changed files with 21478 additions and 1 deletions
118
test/tests/unit/core/event.js
Normal file
118
test/tests/unit/core/event.js
Normal file
|
@ -0,0 +1,118 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'core/event';
|
||||
var DEPS = ['_'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(_);
|
||||
};
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 3 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('publics', function () {
|
||||
|
||||
it('.sub() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.sub);
|
||||
});
|
||||
|
||||
it('.unsub() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.unsub);
|
||||
});
|
||||
|
||||
it('.pub() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.pub);
|
||||
});
|
||||
|
||||
it('works', function () {
|
||||
|
||||
var topic = 'topic';
|
||||
var arg1 = 'arg1';
|
||||
var arg2 = 'arg2';
|
||||
var arg3 = 'arg3';
|
||||
var subSpy = sinon.spy();
|
||||
|
||||
var instance = this.applyFn();
|
||||
instance.sub(topic, subSpy);
|
||||
instance.pub(topic, arg1, arg2, arg3);
|
||||
|
||||
assert.isTrue(subSpy.calledOnce);
|
||||
assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
|
||||
|
||||
instance.pub(topic, arg1, arg2);
|
||||
|
||||
assert.isTrue(subSpy.calledTwice);
|
||||
assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
|
||||
assert.deepEqual(subSpy.secondCall.args, [arg1, arg2]);
|
||||
|
||||
instance.unsub(topic, subSpy);
|
||||
|
||||
assert.isTrue(subSpy.calledTwice);
|
||||
assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
|
||||
assert.deepEqual(subSpy.secondCall.args, [arg1, arg2]);
|
||||
|
||||
instance.pub(topic, arg1);
|
||||
|
||||
assert.isTrue(subSpy.calledTwice);
|
||||
assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
|
||||
assert.deepEqual(subSpy.secondCall.args, [arg1, arg2]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue