From 9f1255290736d907f4bc8af77cd41cdd7aea40e9 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 9 Apr 2013 20:23:58 -0700 Subject: [PATCH] Add `_.once` unit tests. Former-commit-id: cb79b4a5e73ec0cb7bae959693bb14599277ffe0 --- test/test.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/test.js b/test/test.js index c7dca3f72..4850b21e6 100644 --- a/test/test.js +++ b/test/test.js @@ -1972,6 +1972,41 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.once'); + + (function() { + test('should ignore recursive calls', function() { + var count = 0; + + var func = _.once(function() { + count++; + func(); + }); + + func(); + strictEqual(count, 1); + }); + + test('should not throw more than once', function() { + var pass = true; + + var func = _.once(function() { + throw new Error; + }); + + raises(function() { func(); }, Error); + + try { + func(); + } catch(e) { + pass = false; + } + ok(pass); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.parseInt'); (function() {