Browse Source

[fix] else block should short-circuit if already resolved

master
Muthu Kumar 7 years ago
parent
commit
d88741d38b
  1. 3
      .vscode/settings.json
  2. 3
      index.js
  3. 10
      spec/Fuse-spec.js

3
.vscode/settings.json

@ -0,0 +1,3 @@
{
"eslint.enable": false
}

3
index.js

@ -161,6 +161,9 @@ class Fuse extends FuseItem {
* @returns {Fuse} Returns new FuseItem instance * @returns {Fuse} Returns new FuseItem instance
*/ */
else(consequent) { else(consequent) {
/* If a resolve exists, just pass on the instance
until .resolve() is called */
if (this.resolved) return this;
return new FuseItem(this.value, consequent); return new FuseItem(this.value, consequent);
} }

10
spec/Fuse-spec.js

@ -94,4 +94,14 @@ describe("Fuse", () => {
expect(result.resolve()).toBe('default'); expect(result.resolve()).toBe('default');
}); });
it(`Should return 'true'`, () => {
const a = 'ExpectedString';
const result = new Fuse(a)
.is('ExpectedString', () => true)
.else(() => 'default');
expect(result.resolve()).toBe(true);
});
}); });

Loading…
Cancel
Save