mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 00:57:48 +00:00
Add initial test files from lodash v4. (#4172)
* Install test dependencies. * Add initial test files. These files were created using a simplistic AST manipulator using `recast` to preserve formatting. There's bound to be a huge chunk of errors, but this serves as a good start. QUnit was replaced with Mocha, with ES2015 imports running via `esm`. As far as possible, QUnit-specific syntax has been replaced with Mocha's `describe` and `it`, while the native Node.js `assert` module is used for assertions. Files in the `test` directory ending in `.test.js` will be treated as test files. * Add initial passing files to test run.
This commit is contained in:
committed by
John-David Dalton
parent
7606ea3e25
commit
d5ef31929a
67
test/delay.js
Normal file
67
test/delay.js
Normal file
@@ -0,0 +1,67 @@
|
||||
import assert from 'assert';
|
||||
import { slice } from './utils.js';
|
||||
import delay from '../delay.js';
|
||||
|
||||
describe('delay', function() {
|
||||
it('should delay `func` execution', function(done) {
|
||||
var pass = false;
|
||||
delay(function() { pass = true; }, 32);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.ok(!pass);
|
||||
}, 1);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.ok(pass);
|
||||
done();
|
||||
}, 64);
|
||||
});
|
||||
|
||||
it('should provide additional arguments to `func`', function(done) {
|
||||
var args;
|
||||
|
||||
delay(function() {
|
||||
args = slice.call(arguments);
|
||||
}, 32, 1, 2);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.deepStrictEqual(args, [1, 2]);
|
||||
done();
|
||||
}, 64);
|
||||
});
|
||||
|
||||
it('should use a default `wait` of `0`', function(done) {
|
||||
var pass = false;
|
||||
delay(function() { pass = true; });
|
||||
|
||||
assert.ok(!pass);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.ok(pass);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should be cancelable', function(done) {
|
||||
var pass = true,
|
||||
timerId = delay(function() { pass = false; }, 32);
|
||||
|
||||
clearTimeout(timerId);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.ok(pass);
|
||||
done();
|
||||
}, 64);
|
||||
});
|
||||
|
||||
it('should work with mocked `setTimeout`', function() {
|
||||
var pass = false,
|
||||
setTimeout = root.setTimeout;
|
||||
|
||||
setProperty(root, 'setTimeout', function(func) { func(); });
|
||||
delay(function() { pass = true; }, 32);
|
||||
setProperty(root, 'setTimeout', setTimeout);
|
||||
|
||||
assert.ok(pass);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user