mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 00:57:48 +00:00
Add _.once tests for memorized return values.
This commit is contained in:
18
test/test.js
18
test/test.js
@@ -6839,33 +6839,33 @@
|
||||
QUnit.module('lodash.once');
|
||||
|
||||
(function() {
|
||||
test('should execute `func` once', 1, function() {
|
||||
test('should execute `func` once', 2, function() {
|
||||
var count = 0,
|
||||
once = _.once(function() { count++; });
|
||||
once = _.once(function() { return ++count; });
|
||||
|
||||
once();
|
||||
once();
|
||||
strictEqual(once(), 1);
|
||||
strictEqual(count, 1);
|
||||
});
|
||||
|
||||
test('should not set a `this` binding', 1, function() {
|
||||
var once = _.once(function() { this.count++; }),
|
||||
test('should not set a `this` binding', 2, function() {
|
||||
var once = _.once(function() { return ++this.count; }),
|
||||
object = { 'count': 0, 'once': once };
|
||||
|
||||
object.once();
|
||||
object.once();
|
||||
strictEqual(object.once(), 1);
|
||||
strictEqual(object.count, 1);
|
||||
});
|
||||
|
||||
test('should ignore recursive calls', 1, function() {
|
||||
test('should ignore recursive calls', 2, function() {
|
||||
var count = 0;
|
||||
|
||||
var once = _.once(function() {
|
||||
count++;
|
||||
once();
|
||||
return ++count;
|
||||
});
|
||||
|
||||
once();
|
||||
strictEqual(once(), 1);
|
||||
strictEqual(count, 1);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user