Comparing version 1.0.0 to 1.0.1
@@ -39,3 +39,3 @@ "use strict"; | ||
this.active = false; | ||
disposeThen(this._end, this._error, this._disposable, x); | ||
disposeThen(this._end, this._error, this._disposable, t, x); | ||
} | ||
@@ -46,3 +46,3 @@ }, { | ||
this.active = false; | ||
disposeThen(this._error, this._error, this._disposable, e); | ||
disposeThen(this._error, this._error, this._disposable, t, e); | ||
} | ||
@@ -57,6 +57,6 @@ }]); | ||
function disposeThen(end, error, disposable, x) { | ||
function disposeThen(end, error, disposable, t, x) { | ||
Promise.resolve(disposable.dispose()).then(function () { | ||
end(x); | ||
}, error); | ||
end(t, x); | ||
}, error.bind(null, t)); | ||
} |
{ | ||
"name": "most-test", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Unit testing tools for Most.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -25,3 +25,3 @@ // Logic borrowed from Drain: https://github.com/cujojs/most/blob/master/lib/runSource.js | ||
this.active = false; | ||
disposeThen(this._end, this._error, this._disposable, x); | ||
disposeThen(this._end, this._error, this._disposable, t, x); | ||
} | ||
@@ -31,10 +31,10 @@ | ||
this.active = false; | ||
disposeThen(this._error, this._error, this._disposable, e); | ||
disposeThen(this._error, this._error, this._disposable, t, e); | ||
} | ||
} | ||
function disposeThen(end, error, disposable, x) { | ||
function disposeThen(end, error, disposable, t, x) { | ||
Promise.resolve(disposable.dispose()).then(function () { | ||
end(x); | ||
}, error); | ||
end(t, x); | ||
}, error.bind(null, t)); | ||
} |
@@ -7,42 +7,12 @@ import most from 'most'; | ||
describe('run()', () => { | ||
describe('run()', () => { | ||
it('returns a test environment', () => { | ||
const stream = most.empty(); | ||
const env = run(stream); | ||
it('returns a test environment', () => { | ||
const stream = most.empty(); | ||
const env = run(stream); | ||
assert.ok('tick' in env); | ||
assert.ok('results' in env); | ||
assert.equal(typeof env.tick, 'function'); | ||
assert.ok(Array.isArray(env.results)); | ||
}); | ||
assert.ok('tick' in env); | ||
assert.ok('results' in env); | ||
assert.equal(typeof env.tick, 'function'); | ||
assert.ok(Array.isArray(env.results)); | ||
}); | ||
it('is easy to use', () => { | ||
const stream = most | ||
.periodic(1000, 0) | ||
.scan(x => x + 1, 0) | ||
.skip(1) | ||
.take(2); | ||
const env = run(stream); | ||
return env.tick(/* advance by 1ms */) | ||
.then(result => { | ||
// Make sure the stream didn't terminate | ||
assert.ok(!('end' in result)); | ||
assert.ok(!('error' in result)); | ||
// Ensure that the initial `periodic` value was emitted | ||
assert.equal(result.events.length, 1); | ||
assert.equal(result.events[0], 1); | ||
// Advance 1000ms; the stream should emit the second event and complete | ||
return env.tick(1000); | ||
}) | ||
.then(result => { | ||
assert.equal(result.events.length, 1); | ||
assert.equal(result.events[0], 2); | ||
assert.ok(result.end); | ||
}); | ||
}); | ||
}); | ||
describe('Test Environment', () => { | ||
@@ -53,3 +23,2 @@ describe('new instance', () => { | ||
const env = run(stream); | ||
assert.equal(env.results.length, 0); | ||
@@ -64,3 +33,3 @@ }); | ||
const result = env.tick(); | ||
assert.ok(result) | ||
assert.ok(result); | ||
assert.ok('then' in result); | ||
@@ -80,3 +49,3 @@ assert.equal(typeof result.then, 'function'); | ||
.then(result => { | ||
assert.deepEqual(env.now, 1); | ||
assert.strictEqual(env.now, 1); | ||
assert.deepEqual(result, {events: []}); | ||
@@ -86,3 +55,3 @@ return env.tick(1); | ||
.then(result => { | ||
assert.deepEqual(env.now, 2); | ||
assert.strictEqual(env.now, 2); | ||
assert.deepEqual(result, {events: [1]}); | ||
@@ -92,3 +61,3 @@ return env.tick(1); | ||
.then(result => { | ||
assert.deepEqual(env.now, 3); | ||
assert.strictEqual(env.now, 3); | ||
assert.deepEqual(result, {events: []}); | ||
@@ -98,3 +67,3 @@ return env.tick(1); | ||
.then(result => { | ||
assert.deepEqual(env.now, 4); | ||
assert.strictEqual(env.now, 4); | ||
assert.deepEqual(result, {events: [2]}); | ||
@@ -104,4 +73,4 @@ return env.tick(2); | ||
.then(result => { | ||
assert.deepEqual(env.now, 6); | ||
assert.deepEqual(result, {events: [3], end: true}); | ||
assert.strictEqual(env.now, 6); | ||
assert.deepEqual(result, {events: [3], end: {value: 3}}); | ||
assert.deepEqual(env.results, [ | ||
@@ -112,10 +81,6 @@ {events: []}, | ||
{events: [2]}, | ||
{events: [3], end: true} | ||
]) | ||
{events: [3], end: {value: 3}} | ||
]); | ||
}); | ||
}); | ||
it('should default to 1ms ticks when no interval argument is specified', () => { | ||
const stream = most.periodic() | ||
}); | ||
}); | ||
@@ -122,0 +87,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
23958
607