diff options
| author | Stephen Blott | 2016-03-18 06:12:55 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2016-03-18 06:12:58 +0000 | 
| commit | 5f1acf3c66d9e128883a7a54409a08a42ab9ea05 (patch) | |
| tree | b4d0950c468ccadd2a055c5e8327eb67010a592c /tests | |
| parent | 307ecffc4b5d1ebfc4e48c09e0f333296d509947 (diff) | |
| download | vimium-5f1acf3c66d9e128883a7a54409a08a42ab9ea05.tar.bz2 | |
Add Utils.makeIdempotent.
The intention is to use this to clean up some of the initialisation
sequences in the front end.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit_tests/utils_test.coffee | 23 | 
1 files changed, 23 insertions, 0 deletions
| diff --git a/tests/unit_tests/utils_test.coffee b/tests/unit_tests/utils_test.coffee index 67c3b333..9b71ca72 100644 --- a/tests/unit_tests/utils_test.coffee +++ b/tests/unit_tests/utils_test.coffee @@ -102,3 +102,26 @@ context "compare versions",      assert.equal -1, Utils.compareVersions("1.40.1", "1.40.2")      assert.equal -1, Utils.compareVersions("1.40.1", "1.41")      assert.equal 1, Utils.compareVersions("1.41", "1.40") + +context "makeIdempotent", +  setup -> +    @count = 0 +    @func = Utils.makeIdempotent (n = 1) => @count += n + +  should "call a function once", -> +    @func() +    assert.equal 1, @count + +  should "call a function once with an argument", -> +    @func 2 +    assert.equal 2, @count + +  should "not call a function a second time", -> +    @func() +    assert.equal 1, @count + +  should "not call a function a second time", -> +    @func() +    assert.equal 1, @count +    @func() +    assert.equal 1, @count | 
